In general:
form.php
<form action=submit.php method=post>
<input type=text name=name>
<input type=submit value=Add>
</form>
submit.php
<?php
$name = $_POST["name"];
echo "Hello $name";
// insert to database
?>
Problem: After fill name in form.php, user press ENTER, data is submitted to submit.php, user press F5 F5 .... What will happend ^^!
Solution: prevent multiple submits
form.php
<?php
session_start();
// verify ready to submit
$_SESSION["ready"] = true;
?>
<form action=submit.php method=post>
<input type=text name=name>
<input type=submit value=Add>
</form>
submit.php
<?php
session_start();
if (!isset($_SESSION["ready"])) {
echo "submit failed";
} else {
$name = $_POST["name"];
echo "Hello $name";
// insert to database
// clear ready submit status, expect new verifing from only form.php
unset($_SESSION["ready"]);
}
?>
Title:
Preventing Multiple Submits
Description:
In general: form.php <form action=submit.php method=post> <input type=text name=name> <input type=submit value=Add> </f...
...
Rating:
4