2013-01-10 18 views
0

我對EWZRecaptcha Bunlde(dev-master)和symfony 2.1.0有問題。 reCaptcha顯示正確,圖像改變,所以我認爲配置沒問題。但reCaptcha未經驗證,提交後,$form->getErrorsAsString()表示:此表單不應包含額外字段。symfony2 EWZRecaptchaBundle extra fields

嗯,我認爲額外的字段是recaptcha_challenge_fieldrecaptcha_response_field,這是從reCaptcha發送的,但我不認爲我錯過了the docu中的某些內容,那麼它們可能會出現什麼問題?

對於驗證我使用的代碼從the docu:(ⅰ也嘗試替代方案中,這是有提到的)在配置

use EWZ\Bundle\RecaptchaBundle\Validator\Constraints as Recaptcha; 
//... 
/** 
* @Recaptcha\True 
*/ 
public $recaptcha; 
//... 

framework: 
    validation: { enable_annotations: true } 

我添加的字段是這樣的:

$builder->add('recaptcha', 'ewz_recaptcha', array(
       'property_path' => false, 
       'attr' => array(
        'options' => array(
         'theme' => 'clean' 
        ) 
       ) 
)); 

也許我忘了一些必不可少的東西,這在第e docu?

回答

0

可能嘗試向構建器添加「約束」選項。我的驗證碼生成器插件看起來是這樣的:

$builder->add('recaptcha', 'ewz_recaptcha', array(
         'attr'   => array(
          'options' => array(
           'theme' => 'red' 
          ) 
         ), 
         'label' => "Verification", 
         'property_path' => false, 
         'constraints' => array(
          new True() 
         ), 
         'help' => "Enter the words in the box for verification purposes." 
        )); 

所以需要添加「使用」聲明的約束:

use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\True; 

然後添加約束選項:

'constraints' => array(
    new True() 
), 
+0

非常感謝您的回答。如前所述,我也嘗試過這種方式。沒有運氣。順便說一下,「幫助」選項不存在。你使用哪個symfony版本? – meme

+0

整個錯誤消息是:'form:錯誤:此表單不應該包含額外的字段。 recaptcha:沒有錯誤!' – meme

+0

'$ builder-> add('recaptcha_challenge_field','hidden',array('property_path'=> false)); $ builder-> add('recaptcha_response_field','hidden',array('property_path'=> false));' – meme

0

終於找到了解!
擺脫extra fields的我加入我的表格類這兩個領域:

$builder->add('recaptcha_challenge_field', 'hidden', array('property_path' => false)); 
$builder->add('recaptcha_response_field', 'hidden', array('property_path' => false)); 

驗證,然後用工程:

use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\True; 
... 
'constraints' => array(
        new True() 
       ) 

註釋不`噸工作對我來說:

use EWZ\Bundle\RecaptchaBundle\Validator\Constraints AS Recaptcha; 
... 
/** 
* @Recaptcha\True 
*/ 
public $recaptcha;