Novalidate isn't working on FOS user registration form

六眼飞鱼酱① 提交于 2019-12-06 21:28:29

The novalidate="novalide" on the div is wrong. You need to place this on the form.

For example like this using the controller

$form = $this->createForm(new TaskType(), $task, array(
    'attr' => array(
           'novalidate' => 'novalidate'
    )
));

Or directly in the view

{{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}

Final result

<form action="/app_dev.php/profile/edit" method="POST" class="fos_user_profile_edit" novalidate="novalidate">
    <div id="fos_user_profile_form">
    // ....
    </div>
</form>

EDIT:

Best solution via the form (for Symfony <= 2.6) WORKS

  /**
   * @param OptionsResolverInterface $resolver
   */
  public function setDefaultOptions(OptionsResolverInterface $resolver)
  {
    $resolver->setDefaults(array(
      'attr'=> array('novalidate'=>'novalidate'),
    ));
  }

Best solution via the form (for Symfony >= 2.7)

The configureOptions() method was introduced in Symfony 2.7. Previously, the method was called setDefaultOptions().

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'attr'=> array('novalidate'=>'novalidate'),
    ));
}

IMPORTANT:

If you're using FOSUserBundle, the configureOptions can't be applied directly on the form tag because this tag is manually called in the bundle views.

Example in the registration_content.html.twig :

<form action="{{ path('fos_user_resetting_reset', {'token': token}) }}" {{ form_enctype(form) }} method="POST" class="fos_user_resetting_reset">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!