homepage Welcome to WebmasterWorld Guest from 67.202.56.112
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
"Confirmation" PHP Page for Form
MC SAS Master




msg:3207052
 5:58 pm on Jan 3, 2007 (gmt 0)

I'm hoping someone here can help me because I am at a complete loss how to get this "idea" of mine to work. I've created a form that takes inputs from users and inserts them into a MYSQL database. So far, I've been able to get the form to connect to the MYSQL db via PHP but ran into a problem with users using their browser's back button.

I want there to be a "confirmation page" so that users can double check the responses before submitting them to the database. This would combat duplicate entries caused by misspellings and user error. Anyone have any ideas how to do this? Below is example code from my files:

--- HTML Code ---

<html>
<head>
<title>Report</title>
</head>
<form action="input.php" method="post">
<h1 align="center"> Report Form</h1><br /><br />
<b>Site:</b>
<form>
<select name="sites">
<option value="First">1st Street </option>
<option value="Baltimore">Baltimore</option>
<option value="UnionStation">Union Station</option>
</select><br />
<b>Department:</b>
<form>
<select name="dept">
<option value="Front">Front Office</option>
<option value="Acct">Accounting</option>
<option value="Corporate">Corporate</option>
</select><br />
<b>Location of Incident:</b>
<form> <input type="text" name="location">
</select><br />
<input type="submit" value="Submit" />
<input type="reset" value="Clear Form" />
</form>
</div>
</body>
</html>

--- PHP File ---
<?php
echo '<br />';
echo 'Site: <b>'.$_POST['sites'].'</b><br />';
echo 'Department: <b>'.$_POST['dept'].'</b><br />';
echo 'Location of wreck: <b>' .$_POST['location'].'</b><br />';?>

 

phpmaven




msg:3207070
 6:14 pm on Jan 3, 2007 (gmt 0)

You can create a confirmation page with a form with hidden input fields on it that hold the values from the previous form.

IE: <input type="hidden" name="dept" value="<? echo $_POST['dept']?>">

The "submit" button could say "Confirm" or whatever. Then that form would when posted actually writes the data to your DB.

The other option, which I would prefer, would be to display a Yes/No JavaScript dialog that displays the form values and then posts the form if the person clicks "Yes".

[edited by: phpmaven at 6:19 pm (utc) on Jan. 3, 2007]

MC SAS Master




msg:3207075
 6:17 pm on Jan 3, 2007 (gmt 0)

Thanks for the response, I'm completely new to this so bear with me. How would I set up these "hidden" fields for the confirmation page and how do I like that page to the DB? What I had tried earlier was calling an PHP page called "output.php" from the "input.php" file but it didn't work. Again, thanks a million for your help.

EDIT:

So, are you saying I would put <input type="hidden" name="dept" value="<? echo $_POST['dept']?>"> into the input.php file? Would the input.php file now be:

<?php
echo '<br />';
echo 'Site: <b>'.$_POST['sites'].'</b><br />';
echo 'Department: <b>'.$_POST['dept'].'</b><br />';
echo 'Location of wreck: <b>' .$_POST['location'].'</b><br />';
<input type="hidden" name="dept" value="<? echo $_POST['dept']?>">
<input type="submit" value="Submit" />
?>

[edited by: MC_SAS_Master at 6:25 pm (utc) on Jan. 3, 2007]

phpmaven




msg:3207092
 6:27 pm on Jan 3, 2007 (gmt 0)

You would create a new script called "confirm.php" or whatever and display the results from the first form. Create a hidden form field for every field on the first form.

For Example:
input type="hidden" name="sites" value="<? echo $_POST['sites']?>"
input type="hidden" name="dept" value="<? echo $_POST['dept']?>"
input type="hidden" name="location" value="<? echo $_POST['location']?>"

That form would then post to your "input.php" script. In fact, if you followed my example above, you shouldn't have to change anything in your "input.php" script.

MC SAS Master




msg:3207128
 6:50 pm on Jan 3, 2007 (gmt 0)

Thanks for all of your help, I really appreciate. I do, however, have one final question for you. My input.php file now looks like this:

<?php
echo '<br />';
echo 'Site: <b>'.$_POST['sites'].'</b><br />';
echo 'Department: <b>'.$_POST['dept'].'</b><br />';
echo 'Location of wreck: <b>' .$_POST['location'].'</b><br />';
?>
<input type="hidden" name="dept" value="<? echo $_POST['dept']?>">
<input type="submit" value="Confirm" />

Unfortunately, when hit the "Confirm" button nothing happens. Any idea as to what I'm doing wrong?

bartainer




msg:3210702
 9:20 pm on Jan 6, 2007 (gmt 0)

Is the information placed between the form tags? I have forgotten the <form> tag and the same thing happened to me. Also, how are you processing (action) the form?

Bartainer

bartainer




msg:3210707
 9:26 pm on Jan 6, 2007 (gmt 0)

When I process my forms, all my html is inserted beneath the PHP code. That I call my "thank you" page (e.g. thankyou.php). I carry my variables echo $name (no hidden fields) over to the next page to personlaize my thank you page.

Once the PHP is processed (validated) then the html will pick up. Html will not show until PHP is processed.

Check your form tags.

MC SAS Master




msg:3212088
 2:13 pm on Jan 8, 2007 (gmt 0)

Thanks for the replies, I finally got the pages to work. Apparently the problem was with a Javascript I was using in the header.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved