How to Prevent HTML Form Re-submission
Sometimes HTML form are resubmitted by pressing Function Key (F5). In this post how to prevent HTML form re-submission. This can be done by following methods.
- Adding different submission URL to action property.
- Using session variable to prevent form re-submission.
In the form tag add different submission URL to action. The sample script as follow.
<form method="post" action="submission_url"> <input type="text" name="form_input" /> <input name="Submit" type="submit" value="Save" /> </form>
By using session variable to prevent form submission. The sample script as follow.
<?PHP
session_start();
if($_SERVER['REQUEST_METHOD']=='POST')
{
$form_reset=$_POST['resubmission'];
if($_SESSION['resubmission']!=$form_reset)
{
$_SESSION['resubmission']=$form_reset;
echo $_POST['form_input'];
}
else
echo "Error:Resubmission";
}
?>
<!DOCTYPE html>
<html lang="en">
<body>
<form method="post">
<input type="text" name="form_input" />
<input name="Submit" type="submit" value="Save" />
<input type="hidden" name="resubmission" value="<? echo date('dmyHis');?>" />
</form>
</body>
</html>

0 Comment