Hello,

I've been attempting to add a ReCAPTCHA to a user registration form (I'm 
using FOSUserBundle to manage users/logins) and while everything seems to 
work fine, I can't get Symfony2 to call the custom validator associated with 
the ReCAPTCHA. I'm using EWZRecaptchaBundle render and validate the 
ReCAPTCHA.

Here's what the author says to do for those that are unfamiliar with this 
bundle:
https://github.com/excelwebzone/EWZRecaptchaBundle/blob/master/README.md

My buildForm() function in my user registration form:

class RegUserFormType extends BaseUserFormType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $currentYear = date('Y');

        $builder->add('username', 'text', array(
            'max_length' => 30
        ));
        $builder->add('email', 'repeated', array(
            'type'       => 'text',
            'max_length' => 255
        ));
        $builder->add('plainPassword', 'repeated', array(
            'type'       => 'password',
            'max_length' => 30
        ));
        $builder->add('birthday', 'birthday', array(
            'months' => range(1, 12),
            'days'   => range(1, 31),
            'years'  => range($currentYear, $currentYear-110),
            'format' => \IntlDateFormatter::LONG
        ));
        $builder->add('eula_agree', 'checkbox');
        
        $builder->add('security', new SecurityCodeType());
    }
}

Here's my SecurityCodeType:

class SecurityCodeType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('recaptcha', 'recaptcha');
    }
    
    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'CFP\\Bundle\\AccountBundle\\Model\\Recaptcha'
        );
    }
}

The data class exists simply so that data associated with the ReCAPTCHA 
never gets persisted in the database. I discard it after attempting to 
validate the fields. My User entity has the following constraints:

    /**
     * @assert:Type(type="CFP\Bundle\AccountBundle\Model\Recaptcha")
     * @recaptcha:True
     */
    protected $security;

All of this renders correctly and I've been able to get the ReCAPTCHA to 
show up properly in any form I add it to. The problem is I can't validate it 
because the isValid() function never gets called. I've stepped through my 
code using Netbeans/Xdebug to verify this. The fields always validate 
regardless of what I enter.

The documentation for this bundle says to use @recaptcha:True to validate a 
particular field and to define an annotation validation namespace in 
config.yml (called 'recaptcha'). The problem is that this never seems to get 
triggered. I've tried putting @recaptcha:True in my data class as well as in 
my User entity and that doesn't seem to work either. Apparently the author 
has this bundle working and other people have been able to get it working as 
well.

I've looked over the documentation for forms and validation several times 
and I'm really not sure what it is that I'm doing wrong. I absolutely need 
some sort of anti-spam mechanism on my registration form and I've run out of 
ideas (and patience) trying to figure out how to get this working. There may 
be something wrong with how I'm approaching this but it seems to make sense 
based on my understanding of how this works.

I've been trying to solve this for days and just can't figure out why this 
isn't working. Thanks in advance!

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to