ruby-on-rails – 在获取数据之前无形的recaptcha提交表单
发布时间:2020-12-17 03:25:29 所属栏目:百科 来源:网络整理
导读:我正在使用recaptcha gem. Rails 5.2. 我有以下表格: = simple_form_for @quote_request_form,url: quote_requests_path,html: {id: "invisible-recaptcha-form"} do |f| .form-group = f.input :name,label: false,placeholder: 'First and Last Name',.fo
我正在使用recaptcha gem. Rails 5.2.
我有以下表格: = simple_form_for @quote_request_form,url: quote_requests_path,html: {id: "invisible-recaptcha-form"} do |f| .form-group = f.input :name,label: false,placeholder: 'First and Last Name',.form-group.actions.mt-5 button.btn.btn-primary.btn-lg.btn-block#submit-btn Submit = invisible_recaptcha_tags ui: :invisible,callback: 'submitInvisibleRecaptchaForm' 我为表单添加了以下javascript: javascript: document.getElementById('submit-btn').addEventListener('click',function (e) { e.preventDefault(); grecaptcha.execute(); }); var submitInvisibleRecaptchaForm = function () { document.getElementById("invisible-recaptcha-form").submit(); }; 我检查控制器中recaptcha的值如下: if verify_recaptcha(model: @quote_request_form) && @quote_request_form.save redirect_to quote_confirm_path,notice: "Your quotation request is being processed" else render :new end 只要我使用e.preventDefault(),它就可以工作;线.如果我删除这一行,我会在recaptcha中失败,我可以在参数中看到recaptcha attriburte正在发送空白数据. 我不明白为什么我需要它,因为没有文档指定它.所以我做错了什么,但我无法弄清楚. 任何人都可以看到我如何解决这个问题? 解决方法
您需要e.preventDefault()语句,否则表单将在recaptcha执行回调之前提交.
发生这种情况是因为没有类型属性的 回到你的情况,要么保留e.preventDefault()语句,要么将type属性设置为button: .form-group.actions.mt-5 button.btn.btn-primary.btn-lg.btn-block#submit-btn type="button" Submit = invisible_recaptcha_tags ui: :invisible,callback: 'submitInvisibleRecaptchaForm' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |