title: Updating a form in Symfony says CSRF token invalid
body: <p>I created a register form to get information to my user table. Now I want to use the same template to update the user information. Furthermore, I don't want user's email or password to be updated.I use the following code to submit the form. 
  $form->submit($request->request->get($form->getName()),false);
  But it says, "The CSRF token is invalid. Please try to resubmit the form". How to fix this?</p>
  
  <p>//This is my controller</p>
  
  <pre><code>/**
   * @Route("/update/{id}", name="update")
   * @param $id
   * @param Request $request
   * @param UserPasswordEncoderInterface $passwordEncoder
   * @param UserRepository $userRepository
   * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
   */
  
  public function updateUser($id,Request $request, UserPasswordEncoderInterface $passwordEncoder, UserRepository $userRepository){
      $user = $userRepository-&gt;find($id);
  
  
      $form = $this-&gt;createFormBuilder($user)
          -&gt;add('email',EmailType::class,[
              'label'=&gt;'Email',
              'required' =&gt; false,
              'attr'=&gt;['placeholder'=&gt;"Email"]
          ])
          -&gt;add('password',RepeatedType::class,[
              'type' =&gt; PasswordType::class,
              'invalid_message' =&gt; 'The password fields must match.',
              'required' =&gt; false,
              'options' =&gt; ['attr' =&gt; ['class' =&gt; 'password-field']],
              'first_options'  =&gt; ['label' =&gt; 'Password','attr'=&gt;['placeholder'=&gt;"Password"]],
              'second_options' =&gt; ['label' =&gt; 'Confirm Password','attr'=&gt;['placeholder'=&gt;"Confirm Password"]],
          ])
          -&gt;add('firstName',TextType::class,['label'=&gt;'First Name',  'attr'=&gt;['placeholder'=&gt;"First Name"]])
          -&gt;add('lastName',TextType::class,['label'=&gt;'Last Name','attr'=&gt;['placeholder'=&gt;"Last Name"]])
          -&gt;add('address',TextareaType::class,['required' =&gt; false,'label'=&gt;'Address','attr'=&gt;['placeholder'=&gt;"Address"]])
          -&gt;add('idNumber',TextType::class,['label'=&gt;'NIC Number','attr'=&gt;['placeholder'=&gt;"NIC Number"]])
          -&gt;add('phoneNumber',TelType::class,['label'=&gt;'Phone Number','attr'=&gt;['placeholder'=&gt;"Phone Number"]])
          -&gt;add('image',FileType::class,['label'=&gt;'Photo','required'=&gt;false,'attr'=&gt;['hidden'=&gt;"hidden", 'accept'=&gt;"image/jpeg, image/png"]])
          -&gt;add('save',SubmitType::class,[
              'label'=&gt;'Register',
              'attr' =&gt; [
                  'class'=&gt;"btn btn-outline-success float-right"
              ]
          ])
          -&gt;getForm();
  
  
  
      $form-&gt;submit($request-&gt;request-&gt;get($form-&gt;getName()),false);
  
          if($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()){
  
              if($user-&gt;getPassword() !=""){
                  $user-&gt;setPassword($passwordEncoder-&gt;encodePassword($user,$user-&gt;getPassword()));
              }
  
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;flush();
              return $this-&gt;redirect($this-&gt;generateUrl('home'));
          }
  
  
  
  
  
  
      return $this-&gt;render('register/update.html.twig', [
          'form'=&gt;$form-&gt;createView(),
      ]);
  
  
  
  
  }
  </code></pre>
  
  <p>// And this is my twig file. </p>
  
  <pre><code>                        &lt;form name="register" id="register_form"  method="post" enctype="multipart/form-data"&gt;
                              &lt;div id="register"&gt;
                                  &lt;div class="container"&gt;
                                      &lt;div class="row"&gt;
                                          &lt;div class="col-sm-5"&gt;
                                              {{ form_errors(form.firstName) }}
                                              {{ form_widget(form.firstName) }}
                                          &lt;/div&gt;
                                          &lt;div class="col-sm-2"&gt;&lt;/div&gt;
                                          &lt;div class="col-sm-5"&gt;
                                              {{ form_errors(form.lastName) }}
                                              {{ form_widget(form.lastName) }}
                                          &lt;/div&gt;
                                      &lt;/div&gt;
  
                                      &lt;div style="margin-top: 0.5cm;"&gt;&lt;/div&gt;
  
                                      &lt;div class="row"&gt;
                                          &lt;div class="col-sm-6"&gt;
                                              {{ form_errors(form.email) }}
                                              {{ form_widget(form.email,{'attr':{'disabled':"disabled"}}) }}
                                          &lt;/div&gt;
                                          &lt;div class="col-sm-1"&gt;&lt;/div&gt;
                                          &lt;div class="col-sm-5"&gt;
  
                                              {{ form_errors(form.idNumber) }}
                                              &lt;input type="text"  id="register_idNumber" placeholder="NIC Number" onkeypress="isInputNumber(event)" pattern="^[0-9]{9}[a-zA-Z]$" value="{{ form.idNumber.vars.value }}" name="register[idNumber]" required="required" class="form-control" " /&gt;                                                    &lt;div class="input-group-append"&gt;
  
                                              &lt;/div&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
  
  
                                      &lt;div style="margin-top: 0.5cm;"&gt;&lt;/div&gt;
  
                                      &lt;div class="row"&gt;
                                          &lt;div class="col-sm-5"&gt;
                                              &lt;div style="margin-top: 0.5cm;"&gt;&lt;/div&gt;
                                              {{ form_errors(form.phoneNumber) }}
                                              &lt;input type="tel" id="register_phoneNumber" value="{{ form.phoneNumber.vars.value }}" name="register[phoneNumber]" onkeypress="isPhone(event)" required="required" placeholder="Phone Number" class="form-control" pattern="^[0-9]{10}$" /&gt;
                                          &lt;/div&gt;
                                          &lt;div class="col-sm-2"&gt;&lt;/div&gt;
  
  
                                      &lt;/div&gt;
  
                                      &lt;div style="margin-top: 0.5cm;"&gt;&lt;/div&gt;
                                      &lt;div class="row" &gt;
                                          &lt;div class="col-sm-7"&gt;
                                              {{ form_errors(form.address) }}
                                              {{ form_widget(form.address) }}
                                          &lt;/div&gt;
                                          &lt;div class="col-sm-1" hidden="hidden"&gt;
                                              {{ form_widget(form.image) }}
                                          &lt;/div&gt;
  
                                      &lt;/div&gt;
  
                                      &lt;div style="margin-top: 0.5cm;"&gt;&lt;/div&gt;
                                      &lt;div class="form-group row"&gt;
                                          &lt;div class="col-sm-7"&gt;
                                              &lt;div class="custom-control custom-checkbox"&gt;
                                                  &lt;input type="checkbox" class="custom-control-input" id="defaultUnchecked" style="float: left"&gt;
                                                  &lt;label class="custom-control-label" for="defaultUnchecked"&gt;Change Password&lt;/label&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;
  
                                      &lt;/div&gt;
                                      &lt;div style="margin-top: 0.5cm;"&gt;&lt;/div&gt;
  
                                      &lt;div id="register_password" &gt;
                                          &lt;div class="form-group row"&gt;
                                              {% for passwordField in form.password %}
                                                  &lt;div class="col-sm-5"&gt;
                                                      {{ form_errors(passwordField) }}
                                                      {{ form_widget(passwordField) }}
                                                  &lt;/div&gt;
                                                  &lt;div class="col-sm-2"&gt;&lt;/div&gt;
                                              {% endfor %}
  
                                          &lt;/div&gt;
                                          &lt;div style="margin-top: 0.5cm;"&gt;&lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
  
                                  {{ form_widget(form.save,{'label':"Update"}) }}
  
                                  {{ form_row(form._token) }}
                                  {{ form_errors(form) }}
  
                          &lt;/form&gt;
  </code></pre>