pascal_22 Posted June 6, 2012 Share Posted June 6, 2012 Hello, I have a little problem, that i'm pretty sure, that can be solve easily but for now, i have no idea. I have a register form, so when user click submit button i do some validation in JS and after a fully validation in PHP. In my Javascript validation, at the beginning of this function i code: function VerifForm() { document.getElementById('btOk').style.visibility = "hidden"; document.getElementById('btReset').style.visibility = "hidden"; document.getElementById('boxLoader').style.visibility = ''; ...... So if JS is enabled, the submit button and reset button are hidden and the loaderbox is displayed when a user click on the submit button. All is working correctly. But if user has javascript disabled, the loaderbox always appear because the code document.getElementById('boxLoader').style.visibility = "hidden"; at the end of the page is not executed due the JS disable and when user click on submit button, my button are not hidden, so, rarely, that some users click twice or three time on it, so it makes double,triple insert in my database... It there a way to stop double/triple submit of a form when JS is disabled? Or hide button....? Thanks Pascal Quote Link to comment https://forums.phpfreaks.com/topic/263778-phphow-to-avoid-multiple-click-on-submit-button/ Share on other sites More sharing options...
.josh Posted June 7, 2012 Share Posted June 7, 2012 use a session variable to keep track of whether or not the form has been submitted. example code your_form_handling_script.php <?php session_start(); if ( !isset($_SESSION['submitted']) ) { // your regular stuff here that checks if $_POST exists, validates form fields, inserts into db, etc... // if all of the above stuff checks out and form is successfully completed // (make sure to only set this if everything is successfully done; you don't // want to set this if visitor failed a validation or something, because then they won't be able to re-submit... $_SESSION['submitted'] = true; } else { // form was already submitted, tell visitor to stop being submit-button-trigger-happy or do nothing or whatever } only problem with this is if visitor clears their cookies it will destroy the session and they can resubmit. Only real way around that is to basically put the form behind a login system and store a flag value in a database or flatfile with the username and instead of using a session variable flag, check the database/flatfile to see if user already submitted. But EVEN THEN, wouldn't stop visitor from creating a new account! But anyways, if you're simply trying to deter trigger-happy people then the above code should work just fine, because beyond that, people are past being trigger-happy and are purposely trying to resubmit. Quote Link to comment https://forums.phpfreaks.com/topic/263778-phphow-to-avoid-multiple-click-on-submit-button/#findComment-1351787 Share on other sites More sharing options...
pascal_22 Posted June 7, 2012 Author Share Posted June 7, 2012 thanks for your answer. I'll try it !! Thanks a lot!!! Pascal Quote Link to comment https://forums.phpfreaks.com/topic/263778-phphow-to-avoid-multiple-click-on-submit-button/#findComment-1351884 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.