0

So I've done this before, without errors, probably symfony2, and now symfony3, probably not a related issue, just sayin. How can I solve this?

Error:

Attempted to call an undefined method named "isSubmitted" of class "Symfony\Component\Form\FormView".
500 Internal Server Error - UndefinedMethodException

Code:

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;
use AppBundle\Entity\Submission;
use Symfony\Component\Form\Extension\Core\Type\TextType;


use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\HttpFoundation\Response;


use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;


class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request)
    {

        $variables = array();

        $submission = new Submission();
        $form = $this->createFormBuilder($submission)
            ->add('name', TextType::class)
            ->add('phonenumber', TextType::class)
            ->add('email', TextType::class)
            ->add('postal', TextType::class)
            ->add('housing', TextType::class)
            ->add('project', TextType::class)
            ->add('motivation', TextType::class)
            ->add('save', SubmitType::class, array('label' => 'Create submission'))
            ->getForm()->createView();


        var_dump($form->isSubmitted());
        die();
        if ($form->isSubmitted() && $form->isValid()) {
            print_r("yeay");
            die();
            $em = $this->getDoctrine()->getManager();
            $em->persist($submission);
            $em->flush();
        }


            // $variables['form'] = $form;
        // replace this example code with whatever you need
        return $this->render('AppBundle::main.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'),
            'form' => $form,
        ]);
    }
}
0

1 Answer 1

2

You've called isSubmitted() on the form view instead of the form. The form view object doesn't have this method.

Create the form like this:

$form = $this->createFormBuilder($submission)
    ->add('name', TextType::class)
    ->add('phonenumber', TextType::class)
    // ...
    ->getForm();

Create the view just before passing it to the template:

return $this->render('AppBundle::main.html.twig', [
    'form' => $form->createView(),
]);
Sign up to request clarification or add additional context in comments.

4 Comments

Ah, I see! Thanks :)
2 more minutes :) btw, now when i post its fine, but isSubmitted is false, do you see more errors in my code?
Stack overflow is NOT your personal debugging service ;)
Ok, we all have good days and bad days, today was not so great, sometimes I dont have my rubber ducky with me ;p link @Jakub Zalas Where do I go then?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.