Forum Moderators: coopster

Message Too Old, No Replies

Keep The User’s Input Showing in The Form

might be a session problem

         

sqlnew

3:49 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



I am working on a model which contains more than ten pages. There is a form on each page to let the user enter the information. I used session to store the user’s input for each form, so I don’t need pass the input information from each form with $_POST[‘smth’] all the way down to the last page which calculates the result based on the input. My question is HOW TO KEEP THE USER’S INPUT SHOWING IN THE FORM, so when the same user wants to do another calculation by changing only a few inputs not all, the user can only change the one he wants to change, all the other information stay the same as the last round of calculation. For example, the program requires the age, # of courses taking, the score for each course. When the user wants to use this model more than once and he/she only need change the score for each course, all the other information still use the input from the first round. Do any of you have any ideas? I hope I have described my question clear enough for you to understand.
Thanks.

jatar_k

4:01 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are we talking about coming back later?

if so then you will need to save the data to somewhere. A database or file would work. Then when they come back, they would have to login or identify themself in some way. Then you could load their base info from the db and present it in the forms if you want.

sqlnew

4:23 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



Thanks for your reply.
I am not meaning if the user come back later. I mean when the user finishes the first round of calculation and wants another one or more rounds of calculation immediately after the first round. So for this case, does the user still need log in?

Thanks again.

jatar_k

4:29 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you still have the session data then just use that.

sqlnew

7:28 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



Thank you for your quick responding.
The session data are still there, but I don't know how to show these data in the corresponding form(text field). My supervisor requires me to show the data in the form when the user does a second or third or more round of calculation.
Thanks again.

jatar_k

7:32 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ah ok

in your form element you would echo the $_SESSION value in the value= part of the input element

example of a text field

<input type='text' name='firstname' value='<?php echo $_SESSION['firstname'];?>'>

obviously your field names are differewnt and your session vars as well but do you get how to do it?

sqlnew

7:53 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



I'll try this. I think I get it. If I have any problem, I may come back and consult you. Thank you very much.

jatar_k

7:54 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



my pleasure

remember for drop downs, radios or checkboxes there are other ways of making them active

you would need to check against your session value and then echo checked or selected depending on the type of element

sqlnew

8:35 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



I have tried with 2 text fileds. It works! I am so glad it works. I have been thought about this problem for weeks and you helped me to get it solved within hours! Thank you so much.
I still have a qestion. How should I do with radio buttons?
Thanks again.

jatar_k

8:47 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



for radio buttons you need to have it 'checked'

so

<input type='radio' name='somename' value='yes'
<?php if ($_SESSION['somevalue'] == 'yes') echo ' checked';?>>

then repeat the same for all other radios in the group, you may need to have a test in each one for that value. It depends on how it is setup

sqlnew

8:51 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



I'll try this. I really appreciate your kind help.