Google Answers Logo
View Question
 
Q: ASP Form Question ( Answered 5 out of 5 stars,   3 Comments )
Question  
Subject: ASP Form Question
Category: Computers > Internet
Asked by: aspnewby-ga
List Price: $10.00
Posted: 08 Jul 2002 08:58 PDT
Expires: 07 Aug 2002 08:58 PDT
Question ID: 37538
I am a newby at ASP so please bare with me.

I have a page containing a form. Lets call this page; page-a. This
form will collect details of the user such as name, address and
contact details. The last question on the form requires an answer of
yes OR no.

These details are now POSTed through to the next page. However, what i
need to do is post the details through to page-b1 if the answer to the
question was "yes" and page-b2 if the answer to the question was "no".

The way i would do something like this normally, is submit the form on
page-a to itself (page-a) and work out with asp whether yes or no was
selected and doing a response.redirect "page-b1" for "yes" and
response.redirect "page-b2" for "no".

Using this method, i end up at the correct page, but I loose all of
the details were entered. I need to retain the details that were
entered in page-a to be used in page-b.

Please feel free to tell me that i have approached this completly the
wrong way.

I have read some of the other questions and i would imagine that there
is a really obvious answer and i should just go and buy an ASP book
and fill the vast holes in my knowledge but for now, there is my
problem.

Thanks in advance.
Answer  
Subject: Re: ASP Form Question
Answered By: xemion-ga on 16 Jul 2002 12:26 PDT
Rated:5 out of 5 stars
 
itayavtalyon-ga stated the best solution.  To be of further service to
you, below is full source code for the solution.

sample code for page-a:
<% if request("yesno") = "true" then 
		response.redirect "pageb.asp?name=" & request("name") & "&address="
& request("address") & "&phone=" & request("phone") & "&yesno=" &
request("yesno")
    elseif request("yesno") = "false" then
		response.redirect "pagec.asp?name=" & request("name") & "&address="
& request("address") & "&phone=" & request("phone") & "&yesno=" &
request("yesno")
	end if
%>
<html>
<head>
</head>
<body>
<form method="post" action="testform.asp">
  Name: 
  <input type="text" name="name">
  <br>
  Address: 
  <input type="text" name="address">
  <br>
  Phone Number: 
  <input type="text" name="phone">
  <br>
  Yes or No: 
  <input type="radio" name="yesno" value="true">
  Yes 
  <input type="radio" name="yesno" value="false">
  No <br>
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>


sample code for page-b or page-c:

<% response.write "Name: " & request("name") & "<br>Address: " &
request("address") & "<br>Phone Number: " & request("phone") %>


I hope this helps you.  Please feel free to ask for clarification if
necessary and if you're satified with the answer, please rate it.
Thanks!
      
xemion-ga
aspnewby-ga rated this answer:5 out of 5 stars

Comments  
Subject: Re: ASP Form Question
From: bruno1378-ga on 11 Jul 2002 21:39 PDT
 
Just to throw this out as an idea... You could always use session
variables to store the info...not the most efficient way, but it would
work.


BRUNO
Subject: Re: ASP Form Question
From: ideal_info-ga on 11 Jul 2002 23:05 PDT
 
I will suggest you the client-side validation using Javascript
approach to determine where the form data should be posted.

The following code will do the trick:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="Javascript">

	function validateForm( objForm ) {
	
		// Checks what is selected
		if( objForm.answer[0].checked == true ) {
		
			objForm.action = "page-b1.asp";
			return( true );
			
		} else if( objForm.answer[1].checked == true ) {
		
			objForm.action = "page-b2.asp";
			return( true );
			
		} else {
		
			alert("Please provide an answer!");
			return( false );
		
		}
	
	}

</SCRIPT>
<BODY>

	<FORM NAME="formUser" METHOD="POST">
	
		<INPUT TYPE="radio" NAME="answer" VALUE="yes">Yes
		<INPUT TYPE="radio" NAME="answer" VALUE="no">No
		
		<BR><BR>
		<INPUT TYPE="submit" ONCLICK="return validateForm( this.form );"
VALUE="Submit form">
	
	</FORM>

</BODY>
</HTML>
Subject: Another way...
From: itayavtalyon-ga on 12 Jul 2002 11:23 PDT
 
Another way to send the data to the other page, rather than using
session variables is to send the data while you redirect to the page
(Get Method):
Such as:  Response.Redirect "pageb-1.asp?name=" & Request.form
("name") and so on.
On page B-1, you can get the data by using the Request.QueryString
function, i.e. Request.QueryString ("name").
- Itay

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy