symfony2 EWZRECAPTCHABLE额外字段
我对EWZRecaptcha Bunlde(开发主机)和symfony 2.1.0有问题。 reCaptcha显示正确,图像发生变化,因此我认为配置正常。但是reCaptcha没有经过验证,在提交后,symfony2 EWZRECAPTCHABLE额外字段,symfony,recaptcha,Symfony,Recaptcha,我对EWZRecaptcha Bunlde(开发主机)和symfony 2.1.0有问题。 reCaptcha显示正确,图像发生变化,因此我认为配置正常。但是reCaptcha没有经过验证,在提交后,$form->getErrorsAsString()说:此表单不应该包含额外的字段 嗯,我认为额外的字段是从recaptcha发送的recaptcha\u challenge\u字段和recaptcha\u response\u字段,但我不认为我遗漏了什么,所以它们有什么问题 为了进行验证,我使用了
$form->getErrorsAsString()
说:此表单不应该包含额外的字段
嗯,我认为额外的字段是从recaptcha发送的recaptcha\u challenge\u字段
和recaptcha\u response\u字段
,但我不认为我遗漏了什么,所以它们有什么问题
为了进行验证,我使用了以下代码:(我还尝试了另一种方法,上面提到过)
在配置中:
framework:
validation: { enable_annotations: true }
我添加了如下字段:
$builder->add('recaptcha', 'ewz_recaptcha', array(
'property_path' => false,
'attr' => array(
'options' => array(
'theme' => 'clean'
)
)
));
$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."
));
也许我忘记了一些文档中没有提到的重要内容?可能尝试向生成器添加“约束”选项。我的recaptcha builder add如下所示:
$builder->add('recaptcha', 'ewz_recaptcha', array(
'property_path' => false,
'attr' => array(
'options' => array(
'theme' => 'clean'
)
)
));
$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”语句:
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\True;
然后添加约束选项:
'constraints' => array(
new True()
),
终于找到了解决办法
为了去掉
额外字段
,我在表单类中添加了这两个字段:
$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;
非常感谢你的回答。如前所述,我也尝试过这种方法。不走运。顺便说一下,“帮助”选项不存在。您使用哪个symfony版本?整个错误消息是:
form:error:此表单不应包含额外字段。没有错误代码>$builder->add('recaptcha\u challenge\u field','hidden',数组('property\u path'=>false))$生成器->添加('recaptcha_响应_字段','hidden',数组('property_path'=>false))代码>对你有用吗?我的表单不需要这些字段。