Page 1 of 1

Php - Mysql form with a preview button?

Posted: Thu Apr 12, 2007 8:15 pm
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!

Posted: Thu Apr 12, 2007 8:21 pm
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.

Posted: Fri Apr 13, 2007 2:31 am
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.