简体   繁体   English

Symfony2 Form config.yml设置为“必需” false

[英]Symfony2 Form config.yml set “required” false

First is an exmaple, we can do this 首先是一个例子,我们可以做到这一点

framework:
    form:            true
    csrf_protection: false

(look at csrf_protection ) (看看csrf_protection

Or set it in formType (but better in config if we don't want do this in all forms we have) 或在formType中进行设置(但如果不想在所有形式的表单中都这样做,最好在config中设置)

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'Eve\CommonBundle\Form\Entity\formLogin',
        'required' => false,
        //'csrf_protection' => false
    ));
}

My choice is declare this in config.yml. 我的选择是在config.yml中声明。 Now, it was an example, question is.... 现在,这是一个例子,问题是...

In FormType we have property such as 在FormType中,我们具有诸如

        'required' => false // disabling html5 check to test POST types

how can i set it in config.yml ? 我如何在config.yml中设置它?

ps: it doesn't work if i set it the same way as 'csrf_protection' ps:如果我将其设置为与“ csrf_protection”相同的方式,它将不起作用

Seems there is no option that disable html5 validation from the config file, check the reference manual (nothing references it) : http://symfony.com/doc/current/reference/configuration/framework.html 似乎没有选项可以从配置文件中禁用html5验证,请查阅参考手册(没有参考手册): http : //symfony.com/doc/current/reference/configuration/framework.html

As it depends more of the view, you should add the valid html attribute "novalidate" to all your form templates and don't manage it in the form class (even if it's possible ^^) : 由于它更多地取决于视图,因此应将有效的html属性“ novalidate”添加到所有表单模板中,并且不要在表单类中进行管理(即使可能是^^):

<form novalidate="novalidate"></form>

The navigator will not validate the required fields (compatible with all navigators !). 导航器不会验证必填字段(与所有导航器兼容!)。 It solves easily your problems ! 它可以轻松解决您的问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM