How to save form data and then re-populate on "submit"

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
mbrittb00
Forum Newbie
Posts: 2
Joined: Tue Dec 08, 2009 10:42 am

How to save form data and then re-populate on "submit"

Post by mbrittb00 »

I have seen this done on various websites so I know it can be done. I have a php file that contains a form with several data entry fields and a section where the results of calculations based on that input data are displayed. What I would like to have happen is when the user clicks the "submit" button on the form php file is redisplayed but with the entry data that was supplied still there (not the default value).

I have actually been able to accomplish this by making a !isset($_COOKIES[]) and setcookies calls for each of the form fields, then have the form 'submit' execute a different php file that sets the COOKIES from the form POST data, then redirects back to the origional php file. The problem with this is that I have will have to have an !isset block for each of the form fields then in the alternate file, I will have to have another set of setcookies calles. This very tedious, and I'm sure there is a better way.

The websites I have found that do this, when I look at the source code (initially before any form entries are made) lists the value of the form fields as "" (i.e. value=""). Then after entering data and clicking submit, that same source code lists the values as the the data that was entered (i.e. value="100"). The form is set to execute a a different php file called cookies.php (action="cookies.php"). Unfortunately I am not able to see the source code for the cookies.php file, so I don't know what is going on there.

Any assistance would be appreciated.

Thanks,
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: How to save form data and then re-populate on "submit"

Post by JNettles »

value="<?php echo $_POST['field']; ?>"
mbrittb00
Forum Newbie
Posts: 2
Joined: Tue Dec 08, 2009 10:42 am

Re: How to save form data and then re-populate on "submit"

Post by mbrittb00 »

Just figured that out as well. Thanks.
Post Reply