Page 1 of 1

Keep form variables

Posted: Sun Nov 03, 2002 6:14 pm
by ruth
Hello everyone,
I am developing a web application with php/mysql. The application has many forms, and each form has 30 to 80 fields. The problem is that once the user submits a form, all form inputs are lost if the user wants to go back to the form by using Back button. This is frustrating because the user has to enter all fields again once the submission fails. I noticed this is happeing because I used authentication to protect the form page. If the user has not logged in, the page is rediected by "header(location: 'login-form')". I tried to define the field values as variables as bellow, but it didn't help.

Code: Select all

<input type="text" name="Name" value="<?php echo $FirstName; ?>" size="10" maxlength="30">
I have to solve this problem, otherwise, the application will not be acceptable by the client :cry: . Please help ... I would appreciate any suggestions.

Thanks in advance.

Ruth

Posted: Sun Nov 03, 2002 6:24 pm
by mydimension
the way i handle these things is to load the form data into a session and then for each input box i have something like:

Code: Select all

<input type="text" name="Name" value="<?php echo $_SESSION&#1111;'FirstName']; ?>" size="10" maxlength="30">
this usually works for me.

Posted: Sun Nov 03, 2002 6:49 pm
by BDKR
Another thing you can do is submit the form back to itself with a different sub-routine that runs when it was submitted. If there is a problem with the submission, it shows the form again and you allready have all the vars to echo back into those fields.

Cheers,
BDKR

Posted: Mon Nov 04, 2002 12:11 am
by ruth
Thank you very much for your reply to my post. Unfortunately, I have not solved my problem.

mydimension: I am a bit worried about using sessions because I have so many fields on a form, and many forms too. In that case, I will need to register too many session variables. Not sure if using an array to store all inputs and put it in a session would make it better. I will give it a try.

BDKR: I also tried to submit the form back to the same page, but it did not work either. I did some thing like:

Code: Select all

if($_POST&#1111;'action']=='save')
&#123;
    do_some_thing_here();
&#125;
else
&#123;
   display_HTML_form();
&#125;
I don't want the form to be displayed again after the submission until the user presses browser's Back button. But I guess in this case the form can not grab the posted inputs back to the fields.

I am sure this is a common problem, and wonder if I have other options.

Thank you very much.

Posted: Mon Nov 04, 2002 12:36 am
by ruth
I have just found a solution: use session_cache_limiter('private') before calling session_start(). It works perfectly.

Thank you for your support.

Posted: Mon Nov 04, 2002 12:41 am
by BDKR
Good! I'm glad you found something that works.

Cheers,
BDKR

Posted: Tue Nov 12, 2002 12:59 pm
by jasonn
I am having the same problem. Very Annoying!

I tried the

Code: Select all

session_cache_limiter("private")
but got nowhere. I tried placing it on the page with the form, the page that the form submitted to, and on both. Nothing is working.

Is there some other way?

jasonn.

Posted: Tue Nov 12, 2002 5:25 pm
by ruth
Jasonn,
My porblem was caused by the use of session variables. So, in my case, session_start() is called at top of a page. Therefore, session_cache_limiter("private") must be the first line on the page. If your problem is not due to the session. This may not solve your problem. Have you tried to use variables for the field values? Some thing like:

Code: Select all

<form method="post" action="action.php">
<input type="text" name="Name" value=<?php echo $Name; ?> >
something_else
</form>
If you can not use the above to solve your problem. I suggest that you use a simple test page just to find out what is the cause of the problem.

Ruth

Posted: Wed Nov 13, 2002 9:09 am
by jasonn
I will give that a try.

Thanks,
jasonn.