Trying to make an example contact form with symfony2

Here I am trying to fill out a contact form and submit it. However, when I fill out the form and click Submit, I have this exception:

UndefinedMethodException: Attempted to call method "bindRequest" on class "Symfony\Component\Form\Form" in /symfony/src/tuto/WelcomeBundle/Form/Handler/ContactHandler.php line 47. 

This is the contents of ContactHandler.php:

namespace tuto \ WelcomeBundle \ Form \ Handler;

use Symfony \ Component \ Form \ Form; use Symfony \ Component \ HttpFoundation \ Request;

 /** * The ContactHandler. * Use for manage your form submitions * * @author Abderrahim */ class ContactHandler { protected $request; protected $form; protected $mailer; /** * Initialize the handler with the form and the request * * @param Form $form * @param Request $request * @param $mailer * */ public function __construct(Form $form, Request $request, $mailer) { $this->form = $form; $this->request = $request; $this->mailer = $mailer; } /** * Process form * * @return boolean */ public function process() { // Check the method if ('POST' == $this->request->getMethod()) { // Bind value with form $this->form->bindRequest($this->request); $data = $this->form->getData(); $this->onSuccess($data); return true; } return false; } /** * Send mail on success * * @param array $data * */ protected function onSuccess($data) { $message = \Swift_Message::newInstance() ->setContentType('text/html') ->setSubject($data['subject']) ->setFrom($data['email']) ->setTo(' xxxx@gmail.com ') ->setBody($data['content']); $this->mailer->send($message); } } 

could you help me?

+4
source share
4 answers

You must replace

 $this->form->bindRequest($this->request); 

FROM

 $this->form->bind($this->request); 

How bindRequest() deprecated.

+14
source

Use $form->handleRequest($request); for processing form submissions - http://symfony.com/doc/current/book/forms.html#handling-form-submissions

+3
source

bindRequest was deprecated and removed, use the submit method instead

+2
source

You must replace

 $this->form->bindRequest($this->request); 

from

 $this->form->bind($this->request); 

how bindRequest() deprecated.

-2
source

Source: https://habr.com/ru/post/925583/


All Articles