Php - Mysql form with a preview button?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ender22
Forum Newbie
Posts: 8
Joined: Thu Apr 12, 2007 11:15 am

Php - Mysql form with a preview button?

Post by Ender22 »

Hey.

I have a php form that adds data to a mysql database but I need some pointers how to go about adding a preview button to the form.

I understand how to check wether the submit button is pressed or wether the preview button is pressed but what I dont get is how to show the user their preview data without losing all the data from the forms themselves.

As far as I know, whenever a form is submitted the page is refreshed so all of the data on the forms would be lost.
Should I somehow save this data and reinsert it to the editable forms, while also showing the data as it would appear as text?

im pretty lost on this right now...

how have others done it in the past?

any help is appreciated... thanks!
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

The preview page could contain a normal HTML form, with the following input element:

Code: Select all

<input type="hidden" name="someVal" value="<?php echo htmlspecialchars($_POST['someVal'])?>" />
One input for every value you need to pass to the next page. Those values would still appear to PHP as $_POST['someVal'] on the following page (as long as the form's method attribute is set to post). You could also store a serialized representation of the $_POST superglobal in the $_SESSION superglobal, though the former is a bit more reliable.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If the values of the form were lost when it was posted it you'd never be able to use post data. With that in mind, the same information that you are capturing for adds/updates can be used for previews and stored, as aaronhall suggested, in a hidden form input element.
Post Reply