Solved

Asp Response.Redirect to target=_blank

Posted on 2011-02-23
2
1,074 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 32

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now