Jump to content


Photo

Keeping values in a form


  • Please log in to reply
3 replies to this topic

#1 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 28 March 2006 - 07:22 PM

How do you keep values in a form which someone has entered.
IE with this forum if you reload your post a topic page it keeps the values you entered in the form.
For some reason i thought it was a header() output but i forgot what and can't find it anywhere now :S.

Any ideas?


You can learn alot from reading the manual

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 March 2006 - 09:08 PM

Do you post a message and then go back a page and are you using FF? I find that FF tends to save your last sent data temporarily and so is a browser based feature rather than a PHP one. I believe the extension SessionSaver does this too.

#3 gavinandresen

gavinandresen
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 30 March 2006 - 12:31 AM

[!--quoteo(post=359406:date=Mar 28 2006, 02:22 PM:name=coldkill)--][div class=\'quotetop\']QUOTE(coldkill @ Mar 28 2006, 02:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
How do you keep values in a form which someone has entered.
[/quote]

Generally, when the form is first submitted you save the values somewhere (a database is a good place).

And when the user goes back, you fetch the values from the database and then display the form with values in the right spots.

Is that what you mean? I have some examples of how I do something like that at [a href=\"http://www.skypaint.com/gavin/code/\" target=\"_blank\"]http://www.skypaint.com/gavin/code/[/a] ....


#4 Javizy

Javizy
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 30 March 2006 - 01:08 AM

I did this before with jsp by keeping an array of validated values (blank strings for invalid values) and printing them in the necessary input elements.

You can easily extend this to highlight the invalid fields by changing the CSS class of the input element.

$values = array("name" => "Jiminy", "address" => "", "Post Code" => "RM7 4RT");

<input type="text" value="<?echo $values["name"]?>" />

I'm not sure for what purpose you need them, but I just wanted to make it more convenient for users who made a mistake.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users