Here I'm trying to fill in a contact form then send it. However when I fill in the form and click on send 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 content 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('[email protected]')
                ->setBody($data['content']);
    $this->mailer->send($message);
}
}
Could you please give me any help !!
You should replace
$this->form->bindRequest($this->request);
With
$this->form->bind($this->request);
As bindRequest() has deprecated.
Use $form->handleRequest($request); to handle form submissions - http://symfony.com/doc/current/book/forms.html#handling-form-submissions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With