Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Asp Response.Redirect to target=_blank

Posted on 2011-02-23
2
Medium Priority
?
1,094 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

670 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