Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Asp Response.Redirect to target=_blank

Posted on 2011-02-23
2
Medium Priority
?
1,099 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 34

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

772 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