form-submit

How to prevent form resubmission when page is refreshed (F5 / CTRL+R)

China☆狼群 提交于 2019-11-25 21:59:11
问题 I have a simple form that submits text to my SQL table. The problem is that after the user submits the text, they can refresh the page and the data gets submitted again without filling the form again. I could redirect the user to another page after the text is submitted, but I want users to stay on the same page. I remember reading something about giving each user a unique session id and comparing it with another value which solved the problem I am having but I forgot where it is. 回答1: Use

Prevent users from submitting a form by hitting Enter

£可爱£侵袭症+ 提交于 2019-11-25 21:41:12
问题 I have a survey on a website, and there seems to be some issues with the users hitting enter (I don\'t know why) and accidentally submitting the survey (form) without clicking the submit button. Is there a way to prevent this? I\'m using HTML, PHP 5.2.9, and jQuery on the survey. 回答1: You can use a method such as $(document).ready(function() { $(window).keydown(function(event){ if(event.keyCode == 13) { event.preventDefault(); return false; } }); }); In reading the comments on the original

Persist variables between page loads

谁说我不能喝 提交于 2019-11-25 21:37:43
问题 I am trying to capture the submit button press of my form and if the form is submitted, the page refreshes and I show a few hidden fields. I would like to capture whether the form has been submitted before or not and if it submitted on reload, I would like to unhide the hidden fields. I was trying to use a global variable to achieve this, however I was unable to make it work properly. Here is what I tried: var clicked = false; $(document).ready(function() { $(\"input[type=\'submit\'][value=\

jquery disable form submit on enter

二次信任 提交于 2019-11-25 20:41:24
I have the following javascript in my page which does not seem to be working. $('form').bind("keypress", function(e) { if (e.keyCode == 13) { e.preventDefault(); return false; } }); I'd like to disable submitting the form on enter, or better yet, to call my ajax form submit. Either solution is acceptable but the code I'm including above does not prevent the form from submitting. zessx If keyCode is not caught, catch which : $('#formid').on('keyup keypress', function(e) { var keyCode = e.keyCode || e.which; if (keyCode === 13) { e.preventDefault(); return false; } }); EDIT: missed it, it's