SectionsType类
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('description')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acm\StoreBundle\Entity\Sections'
));
}
/**
* @return string
*/
public function getName()
{
return 'acm_storebundle_sections';
}
Validation.yml:
Acm\StoreBundle\Entity\Sections:
properties:
name:
- NotBlank:
message: not.valid
- Length:
min: 3
max: 45
我也试过
Acm\StoreBundle\Entity\Sections:
properties:
name:
- NotBlank: {message: "not.valid" }
- Length:
min: 3
max: 45
验证{郎} .yml:
<body>
<trans-unit id="1">
<source>not.valid</source>
<target> enter a valid name</target>
</trans-unit>
</body>
config.yml
validation: { enabled: true }
我试过
validation: { enabled: true, enable_annotations: true }
和
validation: { enabled: true, enable_annotations: false }
和
validation: { enable_annotations: true }
问题是验证器显示“请填写此字段”。带有空条目的消息,并忽略来自Validation.yml文件的消息
任何想法?
答案 0 :(得分:0)
解决方案是添加“novalidate”以禁用html5验证
{{ form(form, {'attr': {'novalidate': 'novalidate'}}) }}