View Full Version : Preview

12-30-2003, 04:22 PM
I'm making a form where users insert data into a database. I have a submit button. I want to have a preview button so they can preview their post without entering it into the database. How might I do that?


12-30-2003, 05:52 PM
Well it's not that difficult. Just take the contents of the form and echo it to the browser. Using sessions would make it easy. Store the contents of the form in the session. On the preview page echo the contents you stored in the session to the page.

12-30-2003, 07:04 PM
Okay, thanks for the reply. Could you show me some example code?

Thanks a lot.

- Stevie

12-30-2003, 07:38 PM
What I've done in the past is set a name attribute on the "submit" form element.

<input type="submit" value="<?php print $btnTxt;?>" name="submit" />

Then my php follows like this...

//set default variables
if($_POST['submit'] && $_POST['submit']=="Verify") {
//display form with contents from previous page
elseif($_POST['submit'] && $_POST['submit']=="Submit") {
//process data and display confirmation page
else {
//no post data, display empty form.

Then all my form elements are something like this..

<input type="text" name="firstName" id="firstName" value="<?php print $fName;?>"/>

Which means for each of the conditions above, I need to set the variables


$fName = $_POST['firstName'];

And so on.