Search code examples
symfonyfieldtokencsrf

Symfony Form, CSRF token missing


Like in the topic, i have problem with CSRF token missing. This is my form:

$builder
            ->add('email', 'email', array(
                'label' => 'Adres e-mail'
            ))
            ->add('userFirstname', 'text', array(
                'label' => 'Imię',
                'required' => false
            ))
            ->add('userLastname', 'text', array(
                'label' => 'Nazwisko',
                'required' => false
            ))
            ->add('userBusiness', 'entity', array(
                'label' => 'Firma',
                'required' => false,
                'class' => 'Cloud\CrmBundle\Entity\RelationContact',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('u')->where("u.type = 'b'");
                },
                'empty_value' => true
            ))
            ->add('old_password', 'password', array(
                'label' => 'Stare hasło',
                'mapped' => false,
                'required' => false
            ))
            ->add('new_password', 'repeated', array(                
                'first_options' => array(
                    'label' => 'Nowe hasło'),
                'second_options' => array(
                    'label' => 'Powtórz nowe hasło'),
                'mapped' => false,
                'required' => false,
                'type' => 'password'
            ));

My view:

<div class="form-horizontal">
            {{ form_row(form.email) }}
            {{ form_row(form.userFirstname) }}
            {{ form_row(form.userLastname) }}
            {{ form_row(form.userBusiness) }}
        {{ form_row(form.old_password) }}
        {{ form_row(form.new_password) }}
        </div>
</div>

What's wrong guys? Any ideas? :( I just don't understand this strange error... What could cause that ?


Solution

  • Probably you've to add this _token by hand because you're trying to display form manually:

    {{ form_widget(form._token) }}