Forum Moderators: coopster

Message Too Old, No Replies

javascript:history.go(-1) - My form looses it's values

         

I Will Make It

9:30 pm on Jun 1, 2006 (gmt 0)

10+ Year Member



Hi there.

Can anyone help?

I'm making a few web forms on my page.
When I press the submit button, I run a validator, to check if the form is filled out properly. If not, I give an error msg, and then I print out a link saying "go back and correct" with href=javascript:history.go(-1) as the url.

This works well. Only problem is that when I press this link, my form looses all of it's values, so if a user does something wrong when filling out the values, he/she has to do it all over again, starting from scratch.

I use sessions, and I'm sure it has something to do with this...

I want the values to still be there when I direct the user back to the form, after the error msg.

Anyone have any suggestions, except putting it all in cookies?

eelixduppy

10:06 pm on Jun 1, 2006 (gmt 0)



>>>I use sessions, and I'm sure it has something to do with this...
If you already have the info stored in sessions then its easy. Just when you print out the form, print it out similar to this:

<input type='text' name='fname' value='<? echo $_SESSION["fname"];?>' /><br />
<input type='text' name='lname' value='<? echo $_SESSION["lname"];?>' /><br />
<input type='text' name='username' value='<? echo $_SESSION["username"];?>' /><br />

Alternately, if you aren't storing them in sessions, then you can just set the printing of the form in a function, and call it if they didn't fill everything out. And instead of using $_SESSION, just use $_POST and it should still work.

Just use the value attribute to set the value!

Good luck!

[edited by: eelixduppy at 10:34 pm (utc) on June 1, 2006]

I Will Make It

10:23 pm on Jun 1, 2006 (gmt 0)

10+ Year Member



aha... what a nice reply!

Thank you very much!
It helped a lot!

eelixduppy

10:27 pm on Jun 1, 2006 (gmt 0)



You're welcome. I'm glad you got it.