Passing data between forms - structured approach

Results 1 to 3 of 3

Thread: Passing data between forms - structured approach

  1. #1
    Join Date
    Dec 1969
    Posts
    75

    Default Passing data between forms - structured approach

    I read an article about structured approach scripting with ASP. In that, author suggests, a form should "post" to itself and a validation routine (client side & server side) should validate and repost or redirect the control to the next page.<BR><BR>My question here is, if the server side validation is successful, then I would like to pass data to the next page. We dont want to use session variables, at the same time we dont want to use the url because the values are visible. Also, I couldnt use the form variables because, once the form is submitted, I validate and if the validation is successful, i need to redirect it. So, I loose my form variables. <BR><BR>Please help......<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    22

    Default RE: Passing data between forms - structured approach

    I&#039ve been working on that problem for some time and there are many different ways you can do this. This is how I have decided to approach the problem:<BR>Setup the first page with input boxes and other form related material, when the user clicks submit you want to send them to a page that has the page you want to pass the variables to...<BR>at the top of the page you have a virtual include with the file that has the error checking, if it&#039s okay then continue else redirect them back to the first page here is an example below of what I have done:<BR><BR>firstpage.asp<BR>-------------<BR>&#060;html&#062;<BR>&#060;body&#062;<BR>&#060; %<BR> dim uName, uAge<BR> uName = Request.Form("UserName")<BR> uAge = Request.Form("UserAge")<BR>%&#062;<BR>&#060;form name = "myForm" action = "secondpage.asp" method = "post"&#062;<BR>&#060;input type = textbox name = "UserName" value = "&#060;%=uName%&#062;"&#062;<BR><BR>&#060;inpu t type = textbox name = "UserAge" value = "&#060;%=uAge%&#062;"&#062;<BR><BR>&#060;input type = submit value = "submit"&#062;<BR>&#060;/form&#062;<BR>&#060;/body&#062;<BR>&#060;/html&#062;<BR><BR>this is my error checking virtual page called error.asp<BR>-----------------------------------<BR>&#060;%<BR> dim userName, userAge<BR> userName = Request.Form("UserName")<BR> userAge = Request.Form("UserAge")<BR> <BR> dim errorFound<BR> errorFound = "no"<BR><BR> if len(userName) &#062; 20 then<BR> errorFound = "yes"<BR> end if<BR><BR> if not isnumeric(userage) then<BR> errorFound = "yes"<BR> end if<BR>%&#062;<BR>&#060;%<BR> if errorFound = "yes" then<BR>%&#062;<BR>&#060;html&#062;<BR>&#060;body& #062;<BR>&#060;font color = red size = 4&#062;There was an error!!!!&#060;/font&#062;<BR><BR>&#060;form name = "errorForm" action = "firstpage.asp" method ="post"&#062;<BR>&#060;input type = hidden name = "UserName" value = "&#060;%=UserName%&#062;" &#062;<BR>&#060;input type = hidden name = "UserAge" value = "&#060;%=UserAge%&#062;" &#062;<BR>&#060;input type = submit value = "Return and fix errors"&#062;<BR>&#060;/form&#062;<BR>&#060;/body&#062;<BR>&#060;/html&#062;<BR>&#060;% else %&#062;<BR> <BR><BR>the final page includes the error.asp<BR>secondpage.asp<BR>--------------<BR>&#060;!--#include virtual="error.asp"--&#062;<BR>&#060;html&#062;<BR>Congratulations there was no error!<BR><BR>You entered for your username: &#060;%=userName%&#062;<BR><BR>You entered for your userage: &#060;%=userAge%&#062;<BR><BR>&#060;/html&#062;<BR>&#060;% end if %&#062;<BR><BR><BR>I hope this is clear enough to understand. Keep in my mind this is not the best solution and I have streamlined it from what I have done, because I use the dictionary object to keep track of errors and stuff. So I don&#039t want flames for how horrible this code is :) It&#039s just for an example. <BR><BR>It works because it validates the input and allows you to use the variables in the second page if the the input is good, it if isn&#039t good it will return the user to the first page and put the<BR>variables back on the page!<BR><BR>Hope this is clear enough<BR>Bhavin

  3. #3
    Join Date
    Dec 1969
    Posts
    75

    Default RE: Passing data between forms - structured approach

    Thanks Bhavin.<BR><BR>This is how we have it now, however, please keep me posted on the improvements. We are trying to be sticky posting the form to itself and validating at the same page. Also, we need to change to label color to red if the entry has an error.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •