2015-11-25 23 views
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)); 
+0

您能告訴我們您的整個表單類型嗎? – Snroki

回答

1

我設法找到一個解決辦法。我誠實不知道這是否是正確的解決方案,但它可以幫助有人堅持這個問題。

$oForm['mail']['first']->addError(new \Symfony\Component\Form\FormError($sMessage));