0

So... basically it. i have a form class and then I render but allways return csrf error.

Form class:

class FormTest extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
           ->add(
                'urlTo',
                'url'
           )
        ->add('submit', 'submit');
    }

public function getName()
{
    return '';
}

}

In the controller:

...
$form = $this->createForm(new FormTest ());

$form->handleRequest($request);

    if ($form->isSubmitted()) {
        if ($form->isValid()) {
            echo 1; die;
        }
    }

When I see in "isSubmited" and try "getData" I just get the url field, the token not, I don't know if it right.

View:

 {{ form_start(form) }}

                {{ form_widget(
                form.linkTo,
                {
                    'attr' : {
                    'class' : 'form-control col-xs-12',
                    'placeholder' : 'url here'
                }
                }
                ) }}

                {{ form_errors(form) }}

                {{ form_widget(
                form.submit,
                {
                    'label' : ' START',
                    'attr' : {
                    'class' : 'btn glyphicon glyphicon-send'
                }
                }
                ) }}

                {{ form_end(form) }}

And that's it, ALLWAYS return csrf token is invalid.

Ok, the problem is that the token is not storage in session... but i don't know why

1 Answers1

0

You need to use form_rest(form) which renders the remaining fields including token or you need to use form_row(form._token) to render the token manually.

form_end(form) is basically just </form>

Marcel Burkhard
  • 3,453
  • 1
  • 29
  • 35