FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php double form submit prevent
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
php double form submit prevent [message #184334] Tue, 24 December 2013 21:15 Go to previous message
pppbbb10 is currently offline  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
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Include gives warning
Next Topic: FF26 crashes with simple code!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 15:30:28 GMT 2024

Total time taken to generate the page: 0.04531 seconds