Jump to content

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>

echo $_SERVER['PHP_SELF']; // note uppercase 

That should almost always work (unless you're running like before 4.3 - even so you really need to update your software ;))

 

Also, a blank action in a form defaults to the page it is on.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.