Solved

Asp Response.Redirect to target=_blank

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

24 Experts available now in Live!

Get 1:1 Help Now