I want to prevent multiple form submission on multiple clicks.
I actually want to insert data into the DB. The process takes a little time, like 2-3 second.
The problem is, that within the 2-3 second the visitor can click about 6-7 times to that button, and it will run the script over and over again.
How can i prevent it?
I tried this code:
<!DOCTYPE html>
<head>
<title>My Form</title>
</head>
<body>
<form action="process.php" method="post">
<input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />
<div>
<label for="name">Name</label>
<input type="text" name="name" />
<div>
<div>
<input type="submit" value="Add Name" onclick="this.disabled=true;return true;" />
</div>
</form>
</body>
</html>
You can disable the submit button when the form submit is in progress like this.So the button will be disabled till the form submit is finished.
first, give an id to your submit button.for example id="myButton"
<input type="submit" value="Submit" id="myButton" />
onsubmit="document.getElementById('myButton').disabled=true;
document.getElementById('myButton').value='Submitting, please wait...';"
The form will be
<form action="test.php" method="post"
onsubmit="document.getElementById('myButton').disabled=true;
document.getElementById('myButton').value='Submitting, please wait...';"
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With