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