Problems With Simple captcha

南笙酒味 提交于 2020-01-06 14:01:11

问题


I have a weird issue .I am using simple captcha in forms in my rails applications. If I am using one captcha in a web page I don't have any problem. But I have a scenario of using three(3) forms in one page in which all the three forms will have the captcha . So that when I refresh the page the captcha data of the three forms are equal.

When we come to database , once the page get loaded the captcha value for one particular id will be created, Without using the captcha if we refresh the page the record is getting updated instead of creating another record, And more over if I open the web page in two tabs and if I submit the form in the first page. It throws an exception which says “ Invalid Captcha”

Can anyone please let me know how to handle multiple captcha's in single page. I am using simple_captcha plugin.

Thanks in-advance


回答1:


I cant see any point using more than one captcha for one page. (I assume that your both forms will submit at the same time.) Because the whole purpose of captcha is to avoid the automatic form submissions.

Second second point is, I'm not sure why you want 3 forms in a single page. You might consider having a one form and filter the identify the parameters accordingly in the controller side.

correct me if I'm mistaken

thanks

sameera




回答2:


Can you explain why do you need new record instead of updated (while refreshing page).

By the way, I had same issue with multiply forms on one page handled by simple_captcha. And my problem was in repeated use of simple_captcha's method show_simple_captcha. It caused repeated database insertions in this case. And Ive made minor changes to the plugin to solve this:

# Line 73 in lib/simple_captcha/view_helpers.rb (in show_simple_captcha method)

options[:field_value] = set_simple_captcha_data(simple_captcha_key, options[:code_type])

changed to:

options[:field_value] = options[:multi] ? simple_captcha_key : set_simple_captcha_data(simple_captcha_key, options[:code_type])

Now I use show_simple_captcha(:multi => true) to generate captcha without database hitting:

<!-- For first captcha on page -->
<%= show_simple_captcha(:object => :foo) %>

<!-- For next captchas on same page -->
<%= show_simple_captcha(:object => :bar, :multi => true) %>


来源:https://stackoverflow.com/questions/3683920/problems-with-simple-captcha

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