?
Solved

Best way to maintain form values after redirect

Posted on 2005-03-20
34
Medium Priority
?
365 Views
Last Modified: 2008-02-01
What is the best way to:

1) User fills out form
2) clicks a link to go to another page
3) I do some stuff on the other page and redirect user back to initial page with values user typed in previously

so how do you redirect then redirect back preventing user from loosing all their data they typed in previously?  I assume cookies which I am a novice at or hidden values possibly?  If so, I guess I'll need a lot of help here and will have to probably post my code so I can get a thorough help on this one.
0
Comment
Question by:dba123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 7
  • 6
  • +3
34 Comments
 
LVL 96

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 400 total points
ID: 13588680
I would suggest you have 4 options:

1.  Use cookies
2.  Use Session variables
3.  Use hidden form values
4.  Put the values into the URL (GET "style")

I don't know which would be preferable over the others.  Personally, I'd probably use the hidden form values in the forms or put the values in the URL.  Cookies seem a bit complex for something like that.  And session variables I think would use system resources unnecessarily.
0
 
LVL 1

Author Comment

by:dba123
ID: 13588686
ok, so when the form submits and I redirect to a totally different page, then the hidden values I had set in the first page are somehow cached?
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 13588697
Form Page with form field names "FName, LName, Phone, Zip"
Submit that page to new page all fields are put into EITHER hidden form values (if a form is on that page as well) or get inserted into the URL.  One thing I'd make an exception for is passwords - those I'd put into session variables.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:dba123
ID: 13588716
Yea, I don't like the having to push to URL due to safety issues.  So in other words, to use hidden fields, all I'm doing is grabbing the field values from the URL and shoving them into new hidden fields on page 2 which is a totally different page.  In that case, I might have to go the cookie route but I don't know how full-proof cookies are when some people have them turned off, or if they erase their cookies somehow.
0
 
LVL 1

Author Comment

by:dba123
ID: 13588721
I may have to do session variables but then there is a performance issue concern.  If I have thousands of people on my site, would that hurt performance if people are using session variables for all posts that are going on which could be by the thousand at any given second.
0
 
LVL 33

Expert Comment

by:sajuks
ID: 13588731
using hidden values are the way to go.
if u r using post then u dont need to grab it from the url
for ex:
u've
<form action="myasp.asp">
<input type="text" name="username" value="">
</form>

and in myasp page u've
<input type="hidden" name="username" value="<%= request.form("username") %>">

Dont waste session variables on this.
0
 
LVL 1

Author Comment

by:dba123
ID: 13588739
ok, so sajuks.  I have used hidden variables for simply checking if a form was submitted.  What I don't get is lets' say I do set a hidden input to a field value.  Then after the user submits the form....or let's say they don't submit the form at all but instead first click on a link in my form that let's say takes them to a picture upload page.  After they browse and upload, they are redirected back. Isn't the hidden value lost at that point from the original page?
0
 
LVL 33

Assisted Solution

by:sajuks
sajuks earned 400 total points
ID: 13588751
if u r opening the upload page in the same locn then u could pass the value from the form page to the upload page and then set it back when u come to the form page.You've to carry froward the hidden variables to the next page.
0
 
LVL 15

Expert Comment

by:gladxml
ID: 13588753
dba123,

have you tried to use...

server.transfer

this will preseved all the submitted values in page... this way if you go to diffferent pages you can still request the form variables...



 


0
 
LVL 1

Author Comment

by:dba123
ID: 13588763
So I could actually use hidden values to also show a user how their post will look like in a view page before they even submit the post as well by just referencing the hidden values rather than submit the pre-post to the database first before they click confirm to actually post the record after they have spell checked, etc?
0
 
LVL 15

Expert Comment

by:gladxml
ID: 13588769
0
 
LVL 1

Author Comment

by:dba123
ID: 13588777
Ok, so lets say I have

main.asp - this page, the user fills in a form and I have set hidden values for all fields.  This page also has alink to upload.asp that the user can click on prior to submitting the form to the database

upload.asp - this is the page the user is redirected to if the  user clicks "upload image" link in mains.asp before clicking submit button in mains.asp

So,

1) If the user clicks to go to the upload.asp page...how do I pass the hidden values to upload.asp from main.asp?
2) Then how do I pass those hidden values from upload.asp back to main.asp when the upload is done allowing the user to continue on filling out the form in main.asp where they left off?
3) So once the user does upload the image, then goes back and finishes the form, I could actually do one more thing...on submit, I could redirect them to viewpost.asp giving them a preview of their post before I even physically submit the record to the database by using the hidden values to render to the page first.  This would be perfect in ensuring that if a u ser cancels or changes their mind, that nothing is submitted unless they verify their post which is great maintenance prevention for me).
0
 
LVL 33

Expert Comment

by:sajuks
ID: 13588779
So I could actually use hidden values to also show a user how their post will look like in a view page before they even submit the post as well by just referencing the hidden values rather than submit the pre-post to the database first before they click confirm to actually post the record after they have spell checked, etc?"
u got that rite
0
 
LVL 1

Author Comment

by:dba123
ID: 13588788
gladxml, unless I'm wrong, it looks like that is for .Net right?  I am using classic ASP here for now...thanks!
0
 

Expert Comment

by:svgharmode
ID: 13588790
Dear Friend ,


I need information from u that r u using the second page for somethign doing or showing soem information or just needed to do some stuff......?

I will another method wich does not need any cookies or session vairaibles....

Please answer this question.....

Cheers:)
Sanjeev
0
 
LVL 33

Expert Comment

by:sajuks
ID: 13588793
Check the first example i've posted that addresses the same points  that u've raised.
0
 
LVL 15

Expert Comment

by:gladxml
ID: 13588799
below is an example.... i just use querysrting values to simulate the action... But you can use it on form with post method...

===just cut and paste save this as any file name...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
if request.QueryString("test1") <> "" then
server.Transfer("testnewpage.asp")
end if
%>
<a href="<%=request.ServerVariables("SCRIPT_NAME")%>?test1=test&test2=test">text</a>


====save this as testnewpage.asp
<%
response.write request.QueryString("test1") & "<br>"
response.write request.QueryString("test2")
%>

You will notice that the first page submit link to itself .. then transfer to the next page and you still get the values...

All the request filled are preserved...

HTH...

Happy programming...
0
 
LVL 15

Expert Comment

by:gladxml
ID: 13588804
No it is not... it supported by classic ASP...
0
 
LVL 15

Expert Comment

by:gladxml
ID: 13588820
Considering your post...
<<<<
main.asp - this page, the user fills in a form and I have set hidden values for all fields.  This page also has alink to upload.asp that the user can click on prior to submitting the form to the database

upload.asp - this is the page the user is redirected to if the  user clicks "upload image" link in mains.asp before clicking submit button in mains.asp
<<<<

Is your upload component handles request coming from a submitted form... Because some upload compnent cannot use request.form collection because of the multipart property... just checking because if not you need to use session variables i or cookies nstead...

HTH...
Happy programming....  
0
 
LVL 1

Author Comment

by:dba123
ID: 13588822
sajuks, so you are referring to your post here:

<form action="myasp.asp">
<input type="text" name="username" value="">
</form>

and in myasp page u've
<input type="hidden" name="username" value="<%= request.form("username") %>">


ok, where i have the mislink is I don't understand in ASP terms how these hidden values are then passed to a totally different asp page name after the user clicks my link  <a href=""/baylinks/upload.asp?action=addpic""><b>Click here to upload a picture</b></a>

I understand how to set up the hidden values in main.asp.  So if I use post action in my form, then you're saying the state is maintained even if I jump to a toally different page than main.asp?

0
 
LVL 33

Expert Comment

by:sajuks
ID: 13588830
gladxml has raised a valid point "Is your upload component handles request coming from a submitted form... Because some upload compnent cannot use request.form collection because of the multipart property"
how are u doing ur upload ?
0
 
LVL 1

Author Comment

by:dba123
ID: 13588840
>>>Is your upload component handles request coming from a submitted form... Because some upload compnent cannot use request.form collection because of the multipart property... just checking because if not you need to use session variables i or cookies nstead...

correct, I can't use Request.Form...but the code for the upload file is in a separate page...not main.asp.  All that is on my upload page is one textfield that holds the filename after the user browses for the file then clicks upload and my code uploads the pic.  Then I want to redirect the user back and shove back in those hidden values back into the form the user was filling out previously on main.asp.
0
 
LVL 1

Author Comment

by:dba123
ID: 13588856
I think everyone is getting confused.  Let me try again.

1) User clicks "Add Post" link
2) User is redirected to the initial input form which is on main.asp
3) User starts filling out stuff in my form
4) User says" oh, I can upload a picture" before all said and done here
5) User decides to click on the "add picture" link on this form
6) User is redirected to upload.asp which simply contains a text field and browse button and upload button
7) User clicks the upload button
8) file is uploaded using the code in upload.asp (there are no request.form in here)
9) User is redirected again back to main.asp so they can finish filling in the rest of the form.  Here is where I want to throw back in what they've typed already and preserver the values from #3 above
10) User clicks Submit
11) I plan on then running a sub on main.asp which simple shows them a previous of the values they have entered by referencing the hidden form values again.
12) User reviews then clicks "Final Submit" button which then writes all this to my database finally.
0
 
LVL 1

Author Comment

by:dba123
ID: 13588869
what I don't get is how do I pass my hidden values I set in main.asp to upload.asp then back to main.asp in the end.  Since I'm using post, is it there all the time?  It thought all variables are lost once you scope out of the same page and go on to a completely different page.

How are they hidden values passed from page to page or is this just automatic in ASP?  I'm needing a very low level explaination on how state is or is not maintained when going from one page to another considering the hidden values and when hidden values loose their value or maintain their value during each jump
0
 
LVL 1

Author Comment

by:dba123
ID: 13588900
And when you say if you are using post, you don't need querystring, what do you mean by that.  I know you mean form action=post but I don't get what you mean in this particular situation...post vs. get.
0
 
LVL 15

Expert Comment

by:gladxml
ID: 13588930
dba123,

hidden field cannot accomplished that for you... even session cannot be applicable with the process that you have posted...

On this part
4) User says" oh, I can upload a picture" before all said and done here

when the user click this link all the infromation will be lost... there is no way or process that tells the page to put it in a hidden fields... or session or cookies... the process will be broken at this point...


0
 
LVL 15

Accepted Solution

by:
gladxml earned 1200 total points
ID: 13588952
Let try to add revise your process logic...

1) User clicks "Add Post" link
2) User is redirected to the initial input form which is on main.asp
3) User starts filling out stuff in my form
<<<this additional page will take care of the
3-a) user submit the page and create a preview page with a upload link...and put all the values in a hidden field.../session variables...
<<<take note that this page is yet save into the db you just only take the values
4) User says" oh, I can upload a picture" before all said and done here

But the only way to preserved your values with using uplaod compnent is by session or cookies

The only drawback of your process is that when the user already upaloaded a picture and then did not submit the details... So the image will be useless...

It would be best to first save it in the db then create a preview page with an upload picture... this way you are sure that the picture uploaded has details...

Just a suggestion...

Happy programming...
0
 
LVL 33

Expert Comment

by:sajuks
ID: 13589010
just a test case 'vnt tested it completely.

assume main page
<form action="myasp.asp" method=post>
<input type="text" name="username" value="<%= request.form("username") %>">
<input type="text" name="email" value="<%= request.form("email") %>">
<input type="submit" value ="Add " >
</form>

<a href="upload.asp?var1=sa&var2=pass">Click to follow link</a>
</a>


upload.asp
<form name="redirectform" action="1.asp" method="post">
<input type="text" name="username" value="<%= Request.QueryString("var1") %>">
<input type="text" name="email" value="<%=Request.QueryString("var2") %>">
<INPUT TYPE="submit">
</form>

myasp.asp
<form>
<input type="text" name="username" value="<%= request.form("username") %>">
<input type="text" name="email" value="<%= request.form("email") %>">
<form>

when u click on the link you can use the request.querystring ( to pass the value u could use javascript )
store the value in the upload page.
when u click on complete ( either on post or redirect pass the values back )

0
 
LVL 10

Expert Comment

by:ThaSmartUno
ID: 13590920
me personally i think you should have the pic upload page to be a popup or even a modal window
0
 
LVL 1

Author Comment

by:dba123
ID: 13590954
thanks a lot...let me try it out...
0
 
LVL 1

Author Comment

by:dba123
ID: 13627810
Ok, I was studying another site.  I noticed they stayed on the same URL/asp page.  I think all they did was run a sub to show just the upload form and that's it.  that way, you can use the same asp page and upload form code as long as that is the only code that is running.

So I mean when I click the upload link, the page refreshes and I guess the hidden values are still there as long as you are on the same asp page?  Then you just check your querystring for a trigger that calls the sub for the upload form and that's the only thing that is rendered when your page refreshes....and then I guess you can still get at the hidden values that are still there?
0
 
LVL 1

Author Comment

by:dba123
ID: 13627822
actually that is how I'm doing it so let me try adding the hidden values....I guess you're saying if I refresh, the hidden values are still there if it's the same asp page?
0
 
LVL 1

Author Comment

by:dba123
ID: 13627867
I read that you can pass hidden form values from page to page, how is this done and why do you say I can't do it in my case if the upload page was technically on a different page (although it's not in this case, it's in an include)  ?
0
 
LVL 1

Author Comment

by:dba123
ID: 13641737
Anyone there?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question