Solved

Asp Response.Redirect to target=_blank

Posted on 2011-02-23
2
1,077 Views
Last Modified: 2012-05-11
Hello, Xperts;

I'm setting up a simple form that has validation built in and I'm fairly new to VBScript. When the form validates, the error opens in the same window forcing the form to refresh, losing all other data. I'd like to keep the code as close as possible to the current construct—calling the error action—so I don't want to get into a response.write("window.open('page.html','_blank')"); type of thing. The line of code is:

if strName = "" then
      Response.Redirect "contact.asp?action=err1"

The whole code send_it.asp code is attached.

Thanks!

Cayce
<%


dim strName, strEmail, strMessage, strAge, optGender

	strName = Request.Form("name") ' holds inputted name
	strEmail = Request.Form("email") ' holds inputted email address
	strMessage = Request.Form("message") ' holds inputted message
	strAge = Request.Form("age") ' holds inputted age
	optGender = Request.Form("gender").Item ' drop down list selection
	
' -- check all fields for empty values --
' -- remove and add new as required --

if strName = "" then
	Response.Redirect "contact.asp?action=err1"
		else if strEmail = "" then
			Response.Redirect "contact.asp?action=err2"
				else if strMessage = "" then
					Response.Redirect "contact.asp?action=err5"
						else if strAge = "" then
							Response.Redirect "contact.asp?action=err3"
								else if optGender = "" then
									Response.Redirect "contact.asp?action=err4"
								end if
						end if
				end if
		end if
end if

' -- begin email send process --

dim objMail

Set objMail = CreateObject("CDONTS.NewMail")

	' -- email variables --
	objMail.To = "dcayce@paulistpress.com"
	objMail.From = Trim(strEmail)
	objMail.Subject = "Feedback"
	objMail.BodyFormat = "0" ' HTML format
	objMail.Body = "Name: " & Trim(strName) & vbCrLf _
				   & "Gender: " & optGender & vbCrLf _
				   & "Age: " & Trim(strAge) & vbCrLf _
				   & "E-Mail Address: " & Trim(strEmail) & vbCrLf _
				   & "Message: " & Trim(strMessage)
	
	' -- send the email --			   
	objMail.Send

' -- clean up object
Set objMail = Nothing

' -- execute confirmation page
Response.Redirect "thanks.html"
%>

Open in new window

0
Comment
Question by:dcayce
2 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 34970047
if you want to do form validation, you might want to consider using client side javascript. This allows you to only submit the form if validation passes.

if thats not an option, can you be a bit more clear on exactly what you're trying to accomplish?
0
 
LVL 18

Accepted Solution

by:
mgfranz earned 500 total points
ID: 34971038
Even if you want to still submit the page back to itself to check validation, use Session Variables to hold the form data.  Of course you will have to first set the page display variable to know if this is the first time you load the page or not.  But after that, once the Session Variables are set you can do whatever you want.  Here is some pseudo-code;

<%
'Lets do your form work

dim strName, strEmail, strMessage, strAge, optGender
Session("strName") = Request.Form("name") ' holds inputted name
Session("strEmail") = Request.Form("email") ' holds inputted email address
Session("strMessage") = Request.Form("message") ' holds inputted message
Session("strAge") = Request.Form("age") ' holds inputted age
Session("optGender") = Request.Form("gender").Item ' drop down list selection

'Now check the contents of each item in the Session Collection
dim i
For Each i in Session.Contents
  If i = "" Then
    'If a blank field is found, do the redirect
    Response.Redirect "contact.asp?action=err"&i&""

Next
%>

Now on your form page you can call the Session Variables simply enough and if blank the form will not fill in.

<% name="name" value="<%=strName%>"/>
Email <input type="text" name="email" value="<%strEmail%>"/>
Message <input type="text" name="message" value="<%strMessage%>"/>
Age <input type="text" name="age" value="<%age%>"/>
Gender <input type="text" name="gender" value="<%strGender%>"/>
<input type="submit" />
</form>
%>

There are other ways to do this of course, client side javascript is one and acceptable, however if the client has javascript turned off you will have problems.

Hope this helps.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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