0
我尝试错误添加到重复类型的邮件领域:添加表格错误重复FormType在控制器
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('lastname', 'text', array(
'required' => true,
'trim' => true,
'max_length' => 255,
'attr' => array('placeholder' => 'lastname',
)
))
->add('mail', 'repeated', array(
'type' => 'email',
'label' => 'email',
'invalid_message' => 'Les Emails doivent correspondre',
'options' => array('required' => true),
'first_options' => array('label' => 'email',
'attr' => array('placeholder' => 'ph_mail_first',
)),
'second_options' => array('label' => 'emailvalidation',
'attr' => array('placeholder' => 'ph_mail_second',
'requiered' => true
)),
'required' => true,
'trim' => true
))
}
public function getName()
{
return 'AddUser';
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'csrf_protection' => true,
));
}
这是我在我的控制器正在做:
$sMessage = $this->container->get('translator')->trans('error');
$oForm->get('mail')->addError(new \Symfony\Component\Form\FormError($sMessage));
此方法与除此之外的其他字段一起工作,错误消息不会出现。我也试图与
GET( 'mail.first')和get( 'mail.first_options')
这工作得很好:
$sMessage = $this->container->get('translator')->trans('error');
$oForm->get('lastname')->addError(new \Symfony\Component\Form\FormError($sMessage));
您能告诉我们您的整个表单类型吗? – Snroki