[英]FormType Validation symfony2
Can you help me plz i can't find the solution 你能帮我吗,我找不到解决方案
<?php
/**
* Description of ContactType
*
* @author Thamer
*/
namespace Common\ContactBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Collection;
class ContactType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('name', 'text', array(
'constraints' => array(
new Length(array('min' => 3)),
new NotBlank()
)
)
)
->add('email', 'email', array(
new NotBlank()
)
)
->add('tel', 'number', array(
'constraints' => array(
new Length(array('min' => 8)),
new NotBlank()
)
)
)
->add('message', 'textarea', array(
'constraints' => array(
new Length(array('min' => 10)),
new NotBlank()
)
)
)
->add('recaptcha', 'ewz_recaptcha')
;
}
public function getName() {
return 'common_contact';
}
}
the error is : 错误是:
The option "0" does not exist. 选项“ 0”不存在。 Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "max_length", "method", "pattern", "post_max_size_message", "property_path", "read_only", "required", "translation_domain", "trim", "validation_groups", "virtual". 定义的选项为:“操作”,“ allow_extra_fields”,“ attr”,“ auto_initialize”,“ block_name”,“ by_reference”,“ cascade_validation”,“ compound”,“ constraints”,“ csrf_field_name”,“ csrf_message”,“ csrf_protection” ”,“ csrf_provider”,“ csrf_token_id”,“ csrf_token_manager”,“数据”,“ data_class”,“已禁用”,“ empty_data”,“ error_bubbling”,“ error_mapping”,“ extra_fields_message”,“ inherit_data”,“ intent” “ invalid_message”,“ invalid_message_parameters”,“ label”,“ label_attr”,“ label_format”,“ mapped”,“ max_length”,“ method”,“ pattern”,“ post_max_size_message”,“ property_path”,“ read_only”,“ required” ”,“ translation_domain”,“修剪”,“ validation_groups”,“虚拟”。 500 Internal Server Error - UndefinedOptionsException 500内部服务器错误-UndefinedOptionsException
In your lines: 在您的行中:
->add('email', 'email', array(
new NotBlank()
)
)
You are passing in new NotBlank()
, but it should be in a constraints option: 您要传入new NotBlank()
,但应在constraints选项中:
->add('email', 'email', array(
'constraints' => array(
new NotBlank()
)
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.