Search code examples
phpsymfonycontrollerrequesthandle

Symfony 2 form Handle request not found


I am making an form in symfony 2 controller.

Here is what it looks like:

    $data = date('Y-m-d');
    $time = date('H:i:s');



    $form = $this->createFormBuilder()

        ->add('incident', 'entity', array('class' => 'MainCoreBundle:Incidenttype', 'multiple' => false, 'expanded' => true))
        ->add('date', 'text',array('data'=>$data))
        ->add('time', 'text',array('data'=>$time))
        ->getForm();

   $form->handleRequest($request);



    if ($form->isValid())

        if ($request->getMethod() == "POST") {

            $message = \Swift_Message::newInstance()

        ->setSubject('SUBJECT')
        ->setFrom('formularz@formularz.pl')
        ->setTo('email@email.com')
        ->setBody(
            $this->renderView(
                'MainAdminBundle:Msg:index.html.twig'));

    $this->get('mailer')->send($message);

    return $this->indexAction($request);

        }

And i want to make an form that have: 2 inputs: - one with current time - second with current date - third with someting from entity (it will be select box)

And on click I want to send it to mail.

And my error is: Call to undefined method Symfony\Component\Form\Form::handleRequest()


Solution

  • Chances are you are using a version of Symfony prior to 2.3

    http://api.symfony.com/2.2/Symfony/Component/Form/Form.html
    This version of the class is missing that method, although it does use bindRequest

    http://api.symfony.com/2.3/Symfony/Component/Form/Form.html
    The method bindRequest was removed in favour of handleRequest.

    Switch your symfony/symfony version in composer.json to ~2.5. It is backwards compatible to 2.3 which is the version you need.