Forum Moderators: coopster
How should I manage to avoid a form to be sent twice
thanks
Henry
What I did in the end was put a unique identifier in each form as a hidden field and store in the database after posting. Then, if someone reposted the same form, and the form's ID was already in the database, I could simply ignore it.
* generate form with unique id (I use an MD5 hash, incremental numbers work fine for non-critical stuff)
* on form submission, check the ID against previously submitted IDs (usually in a database table, a file-based solution might work if you're careful about locking, maybe PHP's own session support might be useful here); if present, ignore the form submission and proceed as usual (or warn user the form has been submitted twice, or whatever); if not, store the ID and process the form.
The principle is fairly simple, the implentation depends on your needs/circumstances, available software etc.
[edit]wrote hardware, meant software[/edit]
[edited by: ExpLarry at 8:36 pm (utc) on July 2, 2004]
$row = mysql_fetch_row($result);
if ($row) {
echo " Form has been already submited. <a href=\"admin.php\">Please enter your admin adn etc..</a>.";
} else {
if($whatever->insertData($table,$array)) {
echo " asasasas <a href=\"****xx.php\">link</a>.";
} else {
echo "error sdfsdfsdf.";
}
}
}
<edit>
your post arrived while I was posting
ptretty much the same concept
thanks
</edit>