Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"This form should not contain extra fields" on step 1 (Symfony2.1) #32

Closed
stevelacey opened this issue Aug 20, 2012 · 1 comment
Closed

Comments

@stevelacey
Copy link

I'm getting this error constantly, and having tried disabling CSRF protection and removing all of my more complicated FormType's, I'm at somewhat of a loss as to what is causing the problem.

Note: I tried removing the event listener, no change.

My FormType looks something like this:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    switch ($options['flowStep']) {
        case 1:

            $builder->addEventListener(FormEvents::PRE_SET_DATA, function($event) use ($builder) {
                $form = $event->getForm();
                $review = $event->getData();

                $factory = $builder->getFormFactory();

                if (!$review->getDealership()) {
                    $field = $factory->createNamed('dealership', 'dealership');
                } else {
                    $field = $factory->createNamed('dealership', 'hidden', $review->getDealership()->getId());
                }

                $form->add($field);
            });

            $builder->add('ratings', 'collection', array(
                'type' => new Rating,
            ));

            $builder->add('comments');

            break;

        case 2:

            $builder->add('department', 'department');

            // $builder->add('employees');

            $builder->add('visited', null, array(
                'label' => 'Date of visited to dealership',
                'format' => 'dd-MM-yyyy',
                'years' => range(date('Y'), date('Y') - 2)
            ));;

            break;
    }
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'ACMEDemo\ReviewBundle\Entity\Review',
        'flowStep' => 1
    ));
}

and my template features:

{% include 'CraueFormFlowBundle:FormFlow:stepField.html.twig' %}

Any thoughts on what the problem might be?

Also, when first loading the form, getCurrentStep returns null and I get a blank form, I have to click next to get to step 1, despite my setDefaultOptions looking like:

    $resolver->setDefaults(array(
        'data_class' => 'ACMEDemo\ReviewBundle\Entity\Review',
        'flowStep' => 1
    ));

Any ideas?

@stevelacey
Copy link
Author

Turned out I wasn't binding the data before creating the form, basic fail.

$this->flow->bind($review);

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant