Home »
Imported messages »
comp.lang.php »
php double form submit prevent
php double form submit prevent [message #184334] |
Tue, 24 December 2013 21:15 |
pppbbb10
Messages: 4 Registered: December 2013
Karma:
|
Junior Member |
|
|
I would like to avoid the double form submit or unwanted submit when first time clicking the link to the form which outputs empty data.
The code below seems to prevent double or single empty form or previous form submit but it also prevents to submit the form when expected.
Main parts of the code as below, all parts on the same php file.
<?php
session_start();
$_SESSION['token'] = md5(session_id() . time());
?>
<!DOCTYPE HTML>
....
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" name="form_submitted">
<input type="hidden" name="token" value="<?php echo $_SESSION['token'] ?>" >
<input type="checkbox" name="catexp[]" value="1">Input1
<input type="checkbox" name="catexp[]" value="2">Input2
<input type="checkbox" name="catexp[]" value="3">Input3
<input type="Submit" name="Submit" >
</form>
<?php
if (isset($_SESSION['token']))
{
if (isset($_POST['token']))
{
if ($_POST['token'] != $_SESSION['token'])
{
// double submit
}
else
{
// FORM PROCESSING HERE
}// else ($_POST['token'] == $_SESSION['token'])
} // if (isset($_POST['token']))
} // if (isset($_SESSION['token']))
?>
How to make the condition go through ?
Thanks
|
|
|
Goto Forum:
Current Time: Fri Nov 22 03:18:23 GMT 2024
Total time taken to generate the page: 0.04801 seconds