Forums
This topic is locked
alternate form actions?
23 Apr 2005 04:47:16 Al Patel posted:
I'm trying to do something simple but can't figure it out. I have a form with a drop down, and depending on if I select value "A" or "B" in that drop down field, I want the form to submit, write data to my database and go to 1 of 2 pages that correspond with the drop down value.Example:
If I select "A" in the drop down - when I click submit on my form, I want to be redirected to page XYZ after writing to my db
If I select "B" in the drop down - when I click submit on my form, I want to be redirected to page ABC after writing to my db
here's my code:
<%
Function GetAction()
If Request.QueryString("Rtype"

GetAction = "localhost/sf/text.asp"
Else
GetAction = " localhost/sf/sitemaintenance.asp"
End If
End Function
%>
...
<body>
<form name="form1" method="post" action="<%=GetAction()%>">
<p>select 1 or 2</p>
<p>
<select name="Rtype" id="Rtype">
<option value="1a">1</option>
<option value="2b" selected>2</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
Thanks, AL
Replies
Replied 23 Apr 2005 15:11:34
23 Apr 2005 15:11:34 Simon Bloodworth replied:
try replacing request.querystring for request.form - as your form uses the POST method.
Simon
DWMX 2004 | ASP | VBScript
Simon
DWMX 2004 | ASP | VBScript
Replied 23 Apr 2005 17:35:54
23 Apr 2005 17:35:54 Al Patel replied:
I get the same results with Request.Form and Request.Querystring which is that the 2nd action always executes and it goes to the "sitemaintenance.asp" page no matter what I select in my drop-down field.
I can't find any good posts on this subject and I am surprised others haven't run into a similar issue.
I can't find any good posts on this subject and I am surprised others haven't run into a similar issue.
Replied 23 Apr 2005 17:39:57
23 Apr 2005 17:39:57 Simon Bloodworth replied:
Could you post the full code please?
Simon
DWMX 2004 | ASP | VBScript
Simon
DWMX 2004 | ASP | VBScript
Replied 23 Apr 2005 18:03:13
23 Apr 2005 18:03:13 Al Patel replied:
Here is my code.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Function GetAction()
If Request.Form("Rtype"
= "1a" then
GetAction = "localhost/sf/text.asp"
Else
GetAction = "localhost/sf/sitemaintenance.asp"
End If
End Function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="<%=GetAction()%>">
<p>select 1 or 2</p>
<p>
<select name="Rtype" id="Rtype">
<option value="1a">1</option>
<option value="2b" selected>2</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Function GetAction()
If Request.Form("Rtype"

GetAction = "localhost/sf/text.asp"
Else
GetAction = "localhost/sf/sitemaintenance.asp"
End If
End Function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="<%=GetAction()%>">
<p>select 1 or 2</p>
<p>
<select name="Rtype" id="Rtype">
<option value="1a">1</option>
<option value="2b" selected>2</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
Replied 23 Apr 2005 19:38:31
23 Apr 2005 19:38:31 Simon Bloodworth replied:
Here some code that will get the form directing to the correct page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%If request.form("run"
<> "" Then %>
<%
If Request.Form("Rtype"
= "1a" then
response.redirect("localhost/sf/text.asp")
Else
response.redirect("localhost/sf/sitemaintenance.asp")
End If
%>
<% End IF %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="rtype.asp">
<p>select 1 or 2</p>
<p>
<select name="Rtype" id="Rtype">
<option value="1a">1</option>
<option value="2b" selected>2</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
<input name="run" type="hidden" id="run" value="run">
</p>
</form>
</body>
</html>
I have just made the page redirect tro itself once the submit button is clicked, this is where the
<%If request.form("run"
<> "" Then %>
is used. you will see that i have put a hidden field in your form called 'run' - so when the form is submitted this value is sent and allows it to run the code afterwards - checking which value had benn chosen and frwarding to the relevant page.
The code at present doesnt enter anything to a database. it is just set to check the form and redirect.
Was this input box going to be on the end of another form?
hope this helps
Simon
DWMX 2004 | ASP | VBScript
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%If request.form("run"

<%
If Request.Form("Rtype"

response.redirect("localhost/sf/text.asp")
Else
response.redirect("localhost/sf/sitemaintenance.asp")
End If
%>
<% End IF %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="rtype.asp">
<p>select 1 or 2</p>
<p>
<select name="Rtype" id="Rtype">
<option value="1a">1</option>
<option value="2b" selected>2</option>
</select>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
<input name="run" type="hidden" id="run" value="run">
</p>
</form>
</body>
</html>
I have just made the page redirect tro itself once the submit button is clicked, this is where the
<%If request.form("run"

is used. you will see that i have put a hidden field in your form called 'run' - so when the form is submitted this value is sent and allows it to run the code afterwards - checking which value had benn chosen and frwarding to the relevant page.
The code at present doesnt enter anything to a database. it is just set to check the form and redirect.
Was this input box going to be on the end of another form?
hope this helps
Simon
DWMX 2004 | ASP | VBScript
Replied 23 Apr 2005 21:06:32
23 Apr 2005 21:06:32 Al Patel replied:
Simon, I see what you're trying to do, but it doesn't work. The form always submits and goes to Rtype.asp (which is the action on the form).
I do need to do a database insert on this page. The only way I can think of creating a workaround is pretty ugly. I can set a session variable = to the Request.QueryString("Rtype"
, then the form action would go to a blank page where it would automatically redirect to the right page based on the value of the session variable. UGLY HUH?
I can't believe I am stumped on this!
I do need to do a database insert on this page. The only way I can think of creating a workaround is pretty ugly. I can set a session variable = to the Request.QueryString("Rtype"

I can't believe I am stumped on this!
Replied 23 Apr 2005 21:52:58
23 Apr 2005 21:52:58 Simon Bloodworth replied:
Hi
First setup your insert behaviour on the page and set it to redirect to itself - once this is done it will give the form a new action MM_INSERT i think.
Now in code view go right to the top of the page and use the same code:
<%If request.form("MM_INSERT"
<> "" Then %>
<%
If Request.Form("Rtype"
= "1a" then
response.redirect("localhost/sf/text.asp")
Else
response.redirect("localhost/sf/sitemaintenance.asp")
End If
%>
<% End IF %>
making sure to change the run value for the value that has been set for the form action.
Now when the form is submitted it will add the data to the DB and then run the code at the top of the page, and because the value exists it will direct to the correct page.....hopefully.
give it a go.
Regards
Simon
DWMX 2004 | ASP | VBScript
First setup your insert behaviour on the page and set it to redirect to itself - once this is done it will give the form a new action MM_INSERT i think.
Now in code view go right to the top of the page and use the same code:
<%If request.form("MM_INSERT"

<%
If Request.Form("Rtype"

response.redirect("localhost/sf/text.asp")
Else
response.redirect("localhost/sf/sitemaintenance.asp")
End If
%>
<% End IF %>
making sure to change the run value for the value that has been set for the form action.
Now when the form is submitted it will add the data to the DB and then run the code at the top of the page, and because the value exists it will direct to the correct page.....hopefully.
give it a go.
Regards
Simon
DWMX 2004 | ASP | VBScript