recaptcha plugin for rails

拈花ヽ惹草 提交于 2020-02-02 05:49:13

问题


I am currently using ambethia's recaptcha plugin for rails. I want to disable the message

"incorrect-captcha-sol"

whenever the user incorrectly enters the wrong recaptcha. How should I go about doing this?

In the source file I get the following tags surrounding the error message

<p class="recaptcha_error">incorrect-captcha-sol</p>

回答1:


The plugin sets the flash (more precisely flash[:recaptcha_error]), i.e. it won't display message automatically. Most likely you have a piece of code that displays all flash messages. Try removing it and/or excluding flash[:recaptcha_error] from being displayed.




回答2:


Because flash[] is an array you could delete element inside it. When we use recaptcha gem, the flash array contain recaptcha_error element, so you just only delete this element with : flash.delete(:recaptcha_error) inside your controller.

For example :

if  verify_recaptcha(:model=>@object,:message=>"Verification code is wrong", :attribute=>"verification code") && @object.save
  #your code if succes
else
  flash.delete(:recaptcha_error)
  #your code if its fail
end

Maybe it could help you. Thanks




回答3:


I have solved this, it is most of the unusual things I have come across, my syntax was previously:

<table>
<form>
<tr><td></td></tr>
</form>
</table>

I changed it to this:

<form>
<table>
<tr><td></td></tr>
</table>
</form>

Because of this switch, suddenly the recaptcha_response_field and recaptcha_challenge_field are posting values back to the form.

I cannot think why this because all MY form variables got posted back before the switch.




回答4:


You might be getting this because you haven't placed a translation file. I think correct way is not to delete flash message but put i18n file

Example:

en:
  recaptcha:
    errors:
      incorrect-captcha-sol: 'Fail'

See https://github.com/ambethia/recaptcha#i18n-support



来源:https://stackoverflow.com/questions/3553451/recaptcha-plugin-for-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!