0

I have been reading this discussion (click here) and I followed the suggestion of passing 'unknown' to the function but it's not working.

After submitting the form, the form does not pass the isValid check.

This is what I used in my controller:

$token = $this->get('form.csrf_provider')->generateCsrfToken('unknown');

I also tried not supplying a value to the function but it's giving me errors. I was hoping by not supplying the value, it will use whatever Symfony uses by default.

I've searched the net for possible list of intentions to use with the generateCrsfToken function and it seems the text I supply is arbritary. I've tried to find the default intention used by Symfony when automatically generating the token (i.e. using {{ form(form) }} to render the form) but I can't find such info.

Any help is greatly appreciated. Thanks a lot

Community
  • 1
  • 1
mrjayviper
  • 2,258
  • 11
  • 46
  • 82

1 Answers1

0

I found this code from the Symfony Form docs

use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class TaskType extends AbstractType
{
    // ...

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class'      => 'Acme\TaskBundle\Entity\Task',
            'csrf_protection' => true,
            'csrf_field_name' => '_token',
            // a unique key to help generate the secret token
            'intention'       => 'task_item',
        ));
    }

    // ...
}

When I added that code into my form class and use the same intention value (i.e. "task_item") using the generateCsrfToken, it works. :)

thanks to those who read my question. :)

mrjayviper
  • 2,258
  • 11
  • 46
  • 82