Symfony2.3 recaptcha在我的表单中不起作用

时间:2015-04-09 15:29:19

标签: recaptcha symfony-2.3 mvcrecaptcha

我正在使用symfony框架开发网站。现在我正在尝试将recaptcha集成到我的表单中,以便我使用这个EWZRecaptchaBundle。 我几乎不能使用1. *版本安装它(不是文档中提到的版本)。我按照文档从here获取密钥,然后我将域名设置为:127.0.0.1,因为我在localhost上。然后我改变了我的formType.php文件:

use EWZ\Bundle\RecaptchaBundle\Validator\Constraints as Recaptcha;

class ContactType extends AbstractType
{
/**
* @Recaptcha\True
*/
public $recaptcha;
    /**
 * @param FormBuilderInterface $builder
 * @param array $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('name')
        ->add('email')
        ->add('subject')
        ->add('message')
        ->add('recaptcha', 'ewz_recaptcha')
    ;
}

并在我的twig文件中添加了recaptcha,如下所示:

{% form_theme form 'EWZRecaptchaBundle:Form:ewz_recaptcha_widget.html.twig' %}

                      {{ form_widget(form.recaptcha, { 'attr': {
                            'options' : {
                                'theme': 'light',
                                'type': 'image'
                            },
                        } })
                     }}

但是当我尝试显示我得到的页面时:The parameter "fr" must be defined. 查看我发现的错误的详细信息:

at appProdDebugProjectContainer ->getParameter ('fr') 
in C:\wamp\www\fstn\vendor\excelwebzone\recaptcha-bundle\EWZ\Bundle\RecaptchaBundle\Form\Type\RecaptchaType.php at line 62  -
    $this->publicKey = $container->getParameter('ewz_recaptcha.public_key');
    $this->secure    = $container->getParameter('ewz_recaptcha.secure');
    $this->enabled   = $container->getParameter('ewz_recaptcha.enabled');
    $this->language  = $container->getParameter($container->getParameter('ewz_recaptcha.locale_key'));
}
/**

它与我安装的Recaptcha Bundle版本有关吗?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试更改此行:

$ this-> language = $ container-> getParameter($ container-> getParameter('ewz_recaptcha.locale_key'));

到此: $ this-> language = $ container-> getParameter('ewz_recaptcha.locale_key');

此问题应在版本2.X中修复