Jump to content

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


mbrittb00

Recommended Posts

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.

i think what you mean is something like this?

 

<form method="POST" action="<?php echo $_SERVER['php_self'] ?>">
<input type="text" name="name" value="<?php echo $_POST['name'] ?> " />
<input type="submit" value="submit" name="submit" />
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.