recaptcha succeeds on view but verify_recaptcha fails in ruby
majuabir opened this issue · comments
My recaptcha widget is works just fine in my frontend. I click it and I get the green checkmark, but invoking verify_recaptcha in my ruby code always returns false for some reason. I took the route of initializing my keys in config/initializers/recaptcha.rb
Recaptcha.configure do |config|
config.site_key = 'x'
config.secret_key = 'y'
end
My test for the veryify_recaptcha goes like this
def captcha_test
valid = false
if verify_recaptcha == true
valid = true
end
return valid
end
I know this looks so redundant but I'm referencing a solution here #219 where jonathanrbowman would make a variable to hold the return of verify_recaptcha which seemed to work for him.
Are there any common mistakes I should consider?
- captcha_test makes no sense ... it's the same as
verify_recaptcha
- print what it returns to see what's going on
- make sure you have the correct site keys and not just x and y
- inspect
recaptcha_reply
- inspect
Recaptcha.skip_env?
- open up the gem and step through https://github.com/ambethia/recaptcha/blob/284b2c79ac965ffbca7c6ceed99797a6cc268d53/lib/recaptcha/adapters/controller_methods.rb
Got it figured out. <%=recaptcha_tags=>
must be included in a form for it to work.
Got it figured out.
<%=recaptcha_tags=>
must be included in a form for it to work.
Thank you! I'd been scratching my head for ages trying to figure out why it wasn't working. You are 100% correct and as soon as I moved <%=recaptcha_tags=> into the form it worked perfectly!