Symfony isValid Il token CSRF falso non è valido

Ho forma ed entity framework; e non capisco perché ho questo errore:

"ERROR: The CSRF token is invalid. Please try to resubmit the form.\n" 

Provo a utilizzare il module per entity framework; e 'data_class' => 'Artel \ ProfileBundle \ Entity \ Teams', e ora con fuori non entity framework; e ho dump ma non abbastanza informazioni:

 FormErrorIterator {#1194 ▼ -form: Form {#1245 ▶} -errors: arrays:1 [▼ 0 => FormError {#1244 ▼ -message: "The CSRF token is invalid. Please try to resubmit the form." #messageTemplate: "The CSRF token is invalid. Please try to resubmit the form." #messageParameters: [] #messagePluralization: null -cause: null -origin: Form {#1245} } ] } UserProfileController.php on line 178: false//this is $form->isValid() UserProfileController.php on line 178: "ERROR: The CSRF token is invalid. Please try to resubmit the form.\n" 

module:

 class TeamInformationType extends AbstractType { private $optionContent; public function __construct($options) { $this->optionContent = $options; } /** * @param FormBuilderInterface $builder * @param arrays $options */ public function buildForm(FormBuilderInterface $builder, arrays $options) { $builder ->add('company', null, arrays('label' => 'Company', 'max_length' => 255)) ->add('technologies', 'skills', arrays('label' => 'Technologies')) ->add('webSite', 'text', arrays('label' => 'Website URL', 'required' => false)) ->add('description', null, arrays('label' => 'Company Description', 'max_length' => 65000, 'required' => false)) ->add('markets', 'chosen', arrays('choices' => $this->optionContent['markets'], 'attr' => arrays('placeholder' => '...'), 'label' => 'Vertical markets', 'required' => true, 'multiple' => true )) ->add('save', 'submit'); } /** * @return string */ public function getName() { return ''; } } 

e la mia AZIONE:

 // Team Information submit public function submitTeamInformationAction($username) { $em = $this->getDoctrine()->getManager(); $request = $this->get('request'); $profileRepository = $this->get('artel.profile.users.repository'); $teamRepository = $this->get('artel.profile.team.repository'); $user_check_username = $profileRepository; $user = $profileRepository->findOneByUsername($username); if (!$user) { throw $this->createNotFoundException('Unable to find a profile.'); } $authenticator = $this->get('artel.profile.authenticator'); if (!$authenticator->check($user)) { throw new AccessDeniedException('Access Denied!'); } $functionHelper = $this->get('artel.profile.additional_function'); $em = $this->getDoctrine()->getManager(); $option['markets'] = $functionHelper->getMarkets(); $team_id = $user->getTeams()->getId(); $team = $teamRepository->findOneById($team_id); $form = $this->createForm(new TeamInformationType($option), $team); if ($request->isMethod('POST')) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); $em->persist($data); $em->flush(); return $this->redirect($this->generateUrl('artel_user_profile_homepage', arrays('username' => $username)) .'#team_infornation'); } } dump($form->getErrors(), $form->isValid(), $form->getErrorsAsString());exit; $response = $this->render('ArtelProfileBundle:' . $this->template . ':form_team_information.html.twig', arrays( 'form' => $form->createView(), 'user' => $user )); return $response; } 

e il mio twig:

 {{ form_errors(teamForm) }} {{ form_start(teamForm, {'action': path('artel_user_team_submit_information', {'username': user.username}), 'method': 'POST'}) }} <div class="form-group"> {{ form_label(teamForm.company, label|default(null), {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(teamForm.company, {'attr': {'class': 'form-control bs-select'}}) }} </div> <div class="form-group"> {{ form_label(teamForm.webSite, label|default(null), {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(teamForm.webSite, {'attr': {'class': 'form-control bs-select'}}) }} </div> <div class="form-group"> {{ form_label(teamForm.description, label|default(null), {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(teamForm.description, {'attr': {'class': 'form-control bs-select'}}) }} </div> <div class="form-group"> {{ form_label(teamForm.markets, label|default(null), {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(teamForm.markets, {'attr': {'class': 'form-control bs-select'}}) }} </div> <div class="form-group skills col-xs-12"> {{ form_label(teamForm.technologies, label|default(null), {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(teamForm.technologies, {'attr': {'class': 'form-control chosen-select input-xlarge'}}) }} </div> <div class="margin-top-20"> {{ form_widget(teamForm.save, {'attr': {'class': 'btn green-haze'}}) }} </div> {{ form_end(infoForm) }} 

È ansible aggiungere un token al model di twig:

 {{ form_widget(form._token) }} 

o non usare la protezione CSRF (non va bene):

 public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(arrays( 'data_class' => 'AppBundle\Entity\Task', 'csrf_protection' => false, 'csrf_field_name' => '_token', // a unique key to help generate the secret token 'intention' => 'task_item', )); } 

Ulteriori informazioni sulla protezione CSRF in Symfony