Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I redirect on submit button click

Status
Not open for further replies.

matrixxx

MIS
Oct 30, 2001
12
US
Basically I have a form that I use to submit data to a database. this works fine. My problem is when I try to redirect the user to a your request has been submitted page. I tried setting a var to do this:
<%
sent = 0
code
sent = 1
if sent = 1 then
response.redirect(&quot;page&quot;)
%>

but all it does is go to the redirect page without letting the user fill out the form.

i was thinkink to use something like onclick redirect, but i am not sure how to do this.

any help would be appreciated

 
Dim set ' <-- declare the var_s
sent=0
.....the rest

> need more info?
:: don't click HERE ::
 
lebisol, I tried that and it didn't work. I found a way to make it work:

<%
If Request.form(&quot;LName&quot;) <> &quot;&quot; Then
Response.redirect(&quot;s_done.htm&quot;)
End If
%>

but I still would like to know how to use the submit button onclick approach.
 
wel... :) ....u never mentioned anyhting about
Request.form... soo [pipe]
but HEY as long as it works for you it is all good.

> need more info?
:: don't click HERE ::
 
show us some more of your code then

in particular your form tag - does it submit to the same page?

if so, the way you have done it (checking if something is in the request.form) is pretty much the only way of checking. A slight variant on that might be:
Code:
If Request.TotalBytes > 0 Then
Basically checks if there was anything sent with the HTTP request (ie, form values). Just makes it easier in the future if for example you remove or change the LName field.

The reason setting a variable doesn't work for you is that ASP is server-side. So once the user sees your form, that variable has been 'thrown out'. Once they submit, its recreated and re-initialised to 0 by the server .. and again destroyed by the time the user sees the page.

You _could_ look into setting a variable in the Session object (associated with each user, and kept across pages).. but your current method is probably better. Then again if they are logging in, you may want to use the session object anyway.. specially if you have lots of 'logged in' pages.

good luck
 
Out of curiousity, will Request.TotalBytes be > 0 if there's a querystring of any kind?
 
It is fairly simple.

Probably cleaner to send the form to another page (action=&quot;xxx.asp&quot; parameter of the form tag).

On the receiving page (all server side), handle the form --- do something for the user. Then, in the server side script, last thing, use the following code:

response.redirect(&quot;thankyou.asp&quot;)

This will take the user to that page. Add a querystring to persist data. You can also deploy logic here..ie if x then response.redirect(&quot;noPermission.asp&quot;) etc

A convention I use is to name the sending page xx.asp, and the receiving page xx_r.asp. You can submit your form to the same page, but sometimes the page becomes large and is not as clean as when separated out.

Jonathan Galpin MCSD
because software should be easy to use
 
clarkin, If Request.TotalBytes > 0 Then

works great. the form tag is as follows
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;<%= Request.ServerVariables(&quot;SCRIPT_NAME&quot;) %>&quot;>

thanks jonathan, but this time all the coding is on one page.

thanks for all your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top