Yii2: Captcha doesn't work with ajax validation

Created on 7 Dec 2013  路  12Comments  路  Source: yiisoft/yii2

In CaptchaAction.validate() a new code is generated after validation if test limit has been exceeded OR the code is valid. Because of that, after validating successfuly with ajax (validateOnSubmit for example) validation fails when processing the form.

In yii1 a new code wasn't generated when validation passed.

I really don't want to mess with my rules when doing ajax validation. Maybe CaptchaAction should detect if it is an ajax request.

Here's the commit with this change: 2356e933eec275f2f81bdb9ecb014fabe6ca116e.

docs

All 12 comments

Without this change, the form protected by captcha may be repeatedly submitted after the first successful submission.

For this reason, in general you should not use ajax validation for captcha check.

I don't agree. There should be a possibility to use ajax validation with forms containing captcha. There should be an option to disable that regeneration and it should be called manually after I validate the form in normal POST request.

This is going to cause much frustration among devs trying to make it work and possibly more issue reports like this.

Now I agree. I can disable ajax validation on the captcha field and don't use validateOnSubmit.

But I think that should be stated in the docs in few places regarding captcha.

Marked as doc issue.

I already added doc to CaptchaValidator.

i have same issue when i use ajax validation Captcha always incorrect please any solution for this ?

@mgitech you can set ajaxValidate = false for captcha field

image
@mgitech Try this ?

@BenasPaulikas solution may not be pretty, but works...

If it works it ain't stupid :dancer:

Was this page helpful?
0 / 5 - 0 ratings