homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

HTML Form ¦ PHP Variable
Simple HTML field question

 2:38 am on Feb 24, 2003 (gmt 0)


I have an HTML form (index.html), and a script that processes that form called process.php. If the person filling out the form happens to miss one of the first three or four fields, process.php displays some errors and provides a link back to the form- I just want, instead of those fields resetting, I want to keep the information they filled in intact.

I thought if the user typed in their name and missed another field- then came back to the form, the field would be populated:

<input type="text" name="fname" value="<?php $_POST['fname'];?>" size="25" />

Not sure what I'm doing wrong.

Any help?



 3:06 am on Feb 24, 2003 (gmt 0)

I'm guessing you are losing the form variables when you click the link back to the form.

Can you include("index.html"); after displaying the errors on your error output page?

Make index.html - index.php and submit the form to itself for processing that way your form variables should still be intact.

Or - my favourite is make your process.php pop up in a javascript window and display your error messages or thankyou message there. That way - the original page with all the user entered data is not jepordised. (especially handy with lengthy forms)


 3:37 am on Feb 24, 2003 (gmt 0)

Thanks for your suggestions...

I tried changing index.html to index.php, but that didn't work. Shouldn't I be able to transfer variables back and forth between two separate pages?


 3:58 am on Feb 24, 2003 (gmt 0)

Yeah you can. But you have to use the post method if you are using the php you provided above.

If you need to use 2 pages for some reason, on your process.php( in your html output ) you need a hidden form with the variables you want to post back to the first form.
<form action="index.php" method="post">
<input type="hidden" name="fname" value="<?php $_POST['fname'];?>">
<input type="submit" name="submit" value="Return to the previous page with your value intact">


Hope this makes sense :)

By the way, instead of using the link, if you just press the back button, are the values still there?


 4:03 am on Feb 24, 2003 (gmt 0)

I use the same setup as keeper.

Try the following with only one file, in that case index.php

First you check if the form was submitted and legit.
for example -> check if the variable exist like : $_POST['submitted'] and the referer is index.php

if that condition is true, do your field validation and if something is wrong, reoutput the form with existing values, but if all fields are ok, output a thank you message or whatever you need (redirect, etc.)

if the condition is false, simply output an empty form.

when you output your form, you can include the following field to check the var submitted

<input type="hidden" name="submitted" value="true" />

hope that helps


[added]Keeper was faster![/added]


 4:09 am on Feb 24, 2003 (gmt 0)

Thanks, let me try these out see if they works.

By the way, instead of using the link, if you just press the back button, are the values still there?

Yes they are.


 4:16 am on Feb 24, 2003 (gmt 0)

Instead of having process.php providing a link back to the original form, how about having it re-create the form with the data provided so far already filled in?

That does away with having to change anything in the original form. Better yet, if they keep leaving (other) required data blank, this will continue to work.


 6:35 am on Feb 24, 2003 (gmt 0)

hi madcat,

process.php will recieve all the values, but that does not mean that index.html will recieve it too, only by clicking a link on the process.php page. the link has to contain the variables in it's query string, like index.html?fname=xxxxx . then index.html will have $_REQUEST['fname'] filled with a value.

you can even turn register_globals [php.net] on and you can use $fname instead.


 2:51 pm on Feb 24, 2003 (gmt 0)

If there are errors in your form and want to send them back and retain values, why not just set the the href of your a tag to "javascript:history.back();"


 12:43 am on Feb 25, 2003 (gmt 0)

Check out this thread:

This may help you out!


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved