recaptcha icon indicating copy to clipboard operation
recaptcha copied to clipboard

verify_recaptcha not prevent saving in ajax form

Open vadjs opened this issue 9 years ago • 3 comments

I'm tying to add recaptcha validation in AJAX form like in a simple usage but i found this error: added verification not prevent new item from saving if captcha verification fails. Full content of create action in controller below:

def create
    @question = Question.new(question_params)
    respond_to do |format|
      if verify_recaptcha(model: @question, message: 'Вы не прошли проверку CAPTCHA. Вы действительно человек?') && @question.save
        format.js
      else        
        format.js
      end
    end
  end

Is there any way to fix this weird bug?

vadjs avatar Dec 22 '15 10:12 vadjs

verify_recaptcha returns false when it fails ... so it should not trigger the save ... can you reproduce this in the example app so I can dig in why it happens ?

grosser avatar Dec 24 '15 03:12 grosser

This project must work. Don't forget to add secret_key_base and recaptcha tokens. Here are 1 record in db:seed for proper working.

Instruction for testing: under the video here are link to call form. Fill all the fields but don't touch recaptcha. Form will be sent successful.

https://github.com/vadimzham/recaptcha-test

vadjs avatar Dec 24 '15 15:12 vadjs

no idea how to get your repo to show a validation ... I pushed a demo example with a model verification and it works fine, please copy this example code or make it break in the demo

grosser avatar Dec 26 '15 02:12 grosser