Forum Moderators: coopster
In my PHP page I have a user form input (action=<?php print $_SERVER["PHP_SELF"]?>) with a Submit button. After submit I process
if(isset($_POST["Submit"])) {
//do some validations...
If the validations fail, I display the applicable error messages. If the validations pass, I continue with a specified process. This is all working fine.
What I'd like to add if validations pass is a "confirmation" form with another Submit button on the same page - i.e. ask some or other question "are you sure this is what you want to do?" followed by "Confirm" button. If "Confirm" is selected, then continue with the specified process.
The only thing that I have not got working correctly is for the specified process to run after the "Confirm" button is pressed. My first error encountered was that I used the same data for both buttons ie <input name="submit" type="submit" value="Submit"> , with the same if(isset($_POST['Submit'])) {, resulting in the specified process being run prior to hitting the confirmation "Submit".
I then realised my error and changed the second button to "Confirm" and adjusted the if(isset($_POST accordingly. It did not work either. The specified process did not run, and no errors were provided. I tried various other changes including if(isset($_POST["Confirm"])&& $_POST["Confirm] == "Confirm") {, to no avail.
Any suggestions will be most appreciated.
Is it possible that the if(isset($_POST['Confirm'])) statement is nested within another if statement which doesnt fire?
Have you tried placing markers at key points in the script to allow you to assess where any logic might be going wrong? For example
echo '1'; //etc
inside each if block?
I then realised my error and changed the second button to "Confirm"
Which attribute did you change to "Confirm"? I believe you need to change the name attribute, so <input name="confirm" type="submit" value="Confirm"> then check for if(isset($_POST['confirm']))
To debug, add this to the beginning of your script:
echo "<pre>"; var_export($_POST); echo "</pre>";
This'll give you a dump of eveything in $_POST. Hope this helps.
if(empty($messages)) { //All validations have passed
//NEW CODE INSERTED 11 JULY 2007 - Add confirmation of action button
?>
<table width=30% align=center BORDER=1 bgcolor=#FF0000 cellpadding=5 cellspacing=1>
<form action="<?php print $_SERVER["PHP_SELF"]?>" method="POST">
<tr><td style="text-align:center;"><b><font face="verdana" size="3" color="#FFFFFF">
<b><u>CONFIRMATION</u></b></font><br></td></tr>
<tr><td style="text-align:center;"><font face="verdana" size="2" color="#FFFFFF">
ARE YOU SURE YOU WISH TO UNPUBLISH CV FOR RECORD REF <b><?php print ($_POST["id"])?></b></font></td></tr>
<tr><td align="center"><input name="Confirm" type="submit" tabindex="1" value="Confirm"></td></tr>
</form></table>
<?php
if(isset($_POST["Confirm"])) {
//END OF NEW CODE INSERT 11 JULY 2007 - the form does display correctly, incl ID
$queryun="UPDATE register SET expirydate = '0000-00-00', viewable = 'No' WHERE register.id='".$_POST["id"]."'";
$result=mysql_query($queryun, $link) or die("MySQL query $queryun failed. Error if any: ".mysql_error());
$mssgs = "Data Deleted for ID Reference No. ".$_POST["id"].".";
// Now we send an email to the candidate confirming the deletion.
//more code continues below to end of email script.
Any other suggestions?