Estoy intentando agregar EWZRecaptcha a mi formulario de registro. Mi constructor de la forma de registro es como la siguiente:Symfony2 agregue el campo ReCaptcha al formulario de registro
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('username', 'text')
->add('password')
->add('recaptcha', 'ewz_recaptcha', array('property_path' => false));
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Acme\MyBundle\Entity\User',
);
}
Ahora, ¿cómo puedo añadir la restricción Reconocer texto en el campo código de imagen? He intentado añadir esto a validation.yml:
namespaces:
RecaptchaBundle: EWZ\Bundle\RecaptchaBundle\Validator\Constraints\
Acme\MyBundle\Entity\User:
...
recaptcha:
- "RecaptchaBundle:True": ~
Pero consigo Property recaptcha does not exists in class Acme\MyBundle\Entity\User
error.
Si quito array('property_path' => false)
de las opciones del campo Reconocer texto, me sale el error:
Neither property "recaptcha" nor method "getRecaptcha()" nor method "isRecaptcha()"
exists in class "Acme\MyBundle\Entity\User"
alguna idea de cómo solucionarlo? :)
¡Gran artículo, gracias! – tamir
Desde Symfony 2.1, se debe usar 'mapped = false' en lugar de' property_path = false', ver http://symfony.com/doc/current/reference/forms/types/form.html#property-path y http: //symfony.com/doc/current/reference/forms/types/form.html#mapped, respectivamente. –