How to Disable Multiple Submits in PHP

If a user clicks a "Submit" button multiple times on your PHP form, the form data submits more than once, which can ruin data integrity in a database. You use JavaScript with your PHP code to stop a user from submitting a form more than once. You stop a user from submitting a form more than once by disabling the submission button after the first click.

Instructions

    • 1

      Right-click the PHP file that contains your submission form. Click the "Open With" option and select your PHP editor.

    • 2

      Add the JavaScript code to the PHP form that disables the button. Copy and paste the following code to the main "<form>" definition tag:

      onsubmit="document.getElementById('thebutton').disabled=true;

      Replace "thebutton" with the HTML ID of the submission button.

    • 3

      Include a message to the user that tells the user the form is processing. This message sends feedback to the user, so the user does not think the form is broken. Copy and paste the following code and place it after the disable statement previously inserted:

      document.getElementById('thebutton').value='Your form is processing. Please wait...';

      Replace "thebutton" with the ID of your submission button.

Related Searches:

References

Comments

Related Ads

Featured