我是Html5的新手,所以这个问题不要问我太多……
我正在尝试使用HTML5内置的表单验证。我使用Bootstrap作为我的框架。每次我提交表单时,当它验证时,它会将气泡放在需要修复的表单域的下方。在最终用户看来,它就好像是出现错误的字段(Product Name是出现错误的字段)。我已经包括了我正在获得的屏幕截图。这是我的标记:谢谢你的帮助!
<div class="control-group">
<label class="control-label required" for="product_name">Name</label>
<div class="controls">
<input type="text" id="product_name" name="product[name]" required="required" placeholder="Product Name" class="span12" value="" />
</div>
发布于 2013-03-14 06:35:56
在FormBuilder中,关闭选项require并使用Form Validation。
ProductType.php中的示例
$builder->add('name', 'text', array(
'label' => 'Name',
'required' => false // this will remove the HTML5 error which in my opinion is meh
)); 在你的validation.yml中
Your\AwesomeBundle\Entity\Product:
properties:
name:
- NotBlank: ~ # when you call bindRequest on the form object it will validate the form data against that constraint一定要检查Form Validation documentation,因为从Symfony2.2开始,一些constraints已经更改了。
https://stackoverflow.com/questions/15397076
复制相似问题