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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HelpGetting Script To Make Form Work 2

Status
Not open for further replies.

Petrolhead

Technical User
Mar 13, 2009
27
0
0
Hi there,

I'm wondering if anoyne can help me I've designed an HTML contact form and I'm tryign to write a script to get the form to e-mail the information to me.

I'm better at VBA than ASP so I was wondering if anyone could have a look at the script for me.

Code:
' declare variables
Dim EmailTo
Dim Subject
Dim Name
Dim Subject
Dim E-MailAddress
Dim Message

' get posted data into variables
EmailTo = "tirvine24@gmail.com"
Subject = Trim(Request.Form("Subject")) 
Name = Trim(Request.Form("Name"))  
E-MailAddress = Trim(Request.Form("Email")) 
Message = Trim(Request.Form("Message")) 

' validation
Dim validationOK
validationOK=true
If  (Trim(Name)="")  Then validationOK=false
If (Trim(Subject)="") Then validationOK=false
If (Trim(Email)="") Then validationOK=false
If (Trim(Message)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("error.htm")

' 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("contact-info-thank-you.htm")

The code for the form is as follows:

Code:
<div id="content">
 
<!-- Begin Main Page Content -->
<!-- main content section -->
 
<h1>
Contact
</h1>
<form method="POST" action="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>Feedback
<option value="Suggestion[]">Suggestion
<option value="Problem or typo[]">Problem or typo report
<option value="Other[]">Other
</select>
</td></tr>

<tr>
<td align=left><b>Your message</b><br>
<textarea cols="50" rows="5" name="Message"></textarea></td>
</tr>

<tr><td align=center colspan=2><input type="Submit" value="Submit Message"></td></tr>
</table>
</form>
<br>

</div>  <!-- content -->
 
What kind of error are you getting?

Also, I'm not sure why you've put square brackets after the Subject and options in the Dropdown list.
 
When I click on the submit buttom the web page merely displays the script, and doesn't e-mail anything or display the thank you page.

Also my background is more in VB & VBA, this is my first attempt at programming an ASP script, would like someone to have a quick glance over it and see if I am missing anything.

I'd like to have an in page error handler rather than re-directing to an error page, but I don't know how to do this.

Thanks for the help so far.
 
your if statements without end if are treated as nested if's and the rest of the statements following them are treated as part of the condition.
 
Hi wvdba

I have corrected the code (I think) as shown below.

Do you think it will work correctly now?

Code:
' declare variables
Dim EmailTo
Dim Subject
Dim Name
Dim Subject
Dim E-MailAddress
Dim Message

' get posted data into variables
EmailTo = "tirvine24@gmail.com"
Subject = Trim(Request.Form("Subject")) 
Name = Trim(Request.Form("Name"))  
E-MailAddress = Trim(Request.Form("Email")) 
Message = Trim(Request.Form("Message")) 

' validation
Dim validationOK

If  (Trim(Name)="")  Then validationOK=false
Else:
If (Trim(Subject)="") Then validationOK=false
Else:
If (Trim(Email)="") Then validationOK=false
Else:
If (Trim(Message)="") Then validationOK=false
Else:
validationOK=true
If (validationOK=false) Then Response.Redirect("error.htm")

' 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("contact-info-thank-you.htm")
 
if your script is displaying and not errors or actions ... might be missing your scripting tags

Code:
[b]<%[/b]

YOUR CODE

[b]%>[/b]

and if it's not that then you might have ASP support disabled in IIS or you're operating on a non windows platform... just some permutations for your code showing in the browser

[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
 
Apologies for the late reply.

I have added the scripting tags.

I was running XP Home whcih didn't have IIS. Have now upgraded to XP Pro and installed IIS in it's entirity.

Ie is still displaying the script rather than the success page.

Do I need to configure IIS somehow, I'm just trying to run the contact page from my desktop as the site isn't online yet.
 
as part of iis's installation you have to denote scripting support, but also in each website config in IIS you have to denote the allowable actions of scripts, plus on top of that the file has to have a ".asp" extention, you may need to change folder view settings to show known file exentions to ensure the file is named correctly

[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