Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

response redirect path problem

Status
Not open for further replies.

Petrolhead

Technical User
Mar 13, 2009
27
Hi there,

I have resolved all other issues with my contct script script. I now get a 404 file not found error when I run it.

I believe this is due to a path error on the final response redirect in the code.

the thank-you.html file is in the root directory and the contact.asp script is in a folder named scripts.

Code:
<%

' declare variables
Dim EmailTo
Dim Subject
Dim Name
Dim EMailAddress
Dim Message

' get posted data into variables
EmailTo = "thomas_irvine@live.co.uk"
Subject = Trim(Request.Form("Subject")) 
Name = Trim(Request.Form("Name"))  
EMailAddress = Trim(Request.Form("Email")) 
Message = Trim(Request.Form("Message")) 

' validation
Dim validationOK

If  (Trim(Name)="")  Then 
validationOK=false
ElseIf (Trim(Subject)="") Then
validationOK=false
ElseIf (Trim(Email)="") Then
validationOK=false
ElseIf (Trim(Message)="") Then
validationOK=false
Else validaionOK=true
End If
If (validationOK=false) Then 
Response.Redirect("~/error.html")
Else

' prepare email body text
Dim Body
Body = Body & "Name: " & Name & VbCrLf
Body = Body & "Subject: " & Subject & VbCrLf
Body = Body & "E-MailAddress: " & E-MailAddress & VbCrLf
Body = Body & "Message: " & Message & VbCrLf

' send email 
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail") 
mail.To = EmailTo
mail.Subject = Subject
mail.Body = Body
mail.Send 

' redirect to success page 
Response.Redirect("~/thank-you.html")

End If
%>

I have tried the tilde and the .. method with no success, can anyone help?
 
sorted the path out now it just loads the error file. I seem to be having a bad day with this.

If i post the html for table could anyone point out where I'm going wrong.

Code:
<form method="post" action="./scripts/contact.asp">
<table width="90%" cellspacing="5" cellpadding="5">
<tr>
<td align="left"><b>Your name</b><br />
<input type="text" name="Name" size="30" maxlength="50" id=
"Name" /></td>
</tr>
<tr>
<td align="left"><b>Your email address</b><br />
<input type="text" name="Email" size="30" maxlength="255" id=
"Email" /></td>
</tr>
<tr>
<td align="left"><b>Message Type</b><br />
<select name="Subject" id="Subject">
<option value="Comment" selected="selected">Feedback</option>
<option value="Suggestion">Suggestion</option>
<option value="Problem or typo">Problem or typo report</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr>
<td align="left"><b>Your message</b><br />
<textarea cols="50" rows="5" name="Message" id="Message">
</textarea></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="Submit" value=
"Submit Message" /></td>
</tr>
</table>
</form>
 
You've set a variable here:
Code:
EMailAddress = Trim(Request.Form("Email"))

And then tested it here using a different variable name:
Code:
ElseIf (Trim(Email)="") Then

I'd suggest trying:
Code:
ElseIf (Trim(EMailAddress)="") Then

See if that helps the validation process.
 
Well spotted.

I have changed the variable as suggested but it is still loading the error page

Thanks for the help so far, any other ideas, I'm stumped now...
 
Have you checked the form 'action' link? If the form is on the root then shouldn't action="scripts/contacts.asp" ?

If the form is in another folder then usually it is action="../scripts/contacts.asp"

It's often difficult to ascertain why links go wrong, play with everything and usually you'll stumble across it quite by accident.
 
I think when you dim a variable like that, it is by default "false." And since you have:
Code:
Else validaionOK=true

you'll notice the variable is misspelled and therefore the check will never see validationOK as true. So you'll always end up at the error page.
 
another side note: i noticed the ~'s in your redirect paths.. this is all and well in ASP.NET, and you're using .ASP file extentions meaning they fire as classic ASP, unless oyu've changed your IIS settings for filetypes.

in summary, you're getting errors in classic ASP, by using methods of ASP.NET

and along the lines of variable names, as the others pointed out :

email vs emailaddress
validationOK vs validaionOK
emailaddress vs E-mailaddress
<< this one is MATH, you're gonna get an error from it, and if not CDONTS will puke on you anyway

thirdly : this massive block is basically an invitation to errors..
If (Trim(Name)="") Then
validationOK=false
ElseIf (Trim(Subject)="") Then
validationOK=false
ElseIf (Trim(Email)="") Then
validationOK=false
ElseIf (Trim(Message)="") Then
validationOK=false
Else validaionOK=true
End If
If (validationOK=false) Then
Response.Redirect("~/error.html")
Else....

perhaps this instead:
If (Trim(Name)="") OR (Trim(Subject)="") OR (Trim(Email)="") OR (Trim(Message)="") Then
Response.Redirect("/error.html")
Else
.....


you wont need the variable assignment for the boolean, you also stack any of the conditions into the same T/F so if any are T you just response.redirect, instead of doing all the else conditionals down the line, also removes one more variable to misspell :)



[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
one more note, along with ferrians post, if you use .. instead of ~ :

make sure in IIS parentpaths are enabled or ../ will generate an error as well

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top