Home | Advertising Info5 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Thursday, May 02, 2024  

  Active InfoActive Info  Display List of Info MembersMemberlist  Search The InfoSearch  HelpHelp
  RegisterRegister  LoginLogin
Classic ASP - General
 PowerASP Code Help Area : Classic ASP - General
Subject Info: CDOSYS Self Submitting "Contact Us" Form A d d  -  P o s tAdd P o s t
Author
Message << Prev Info | Next Info >>
ka3wjz
Newbie
Newbie
Avatar

Joined: April/25/2006
Location: United States
Online Status: Offline
Info: 3
Added: April/25/2006 at 12:23pm | IP Logged Quote ka3wjz

This one page form is great. But can it be split into two separate files. One as the form and the other as the form processor? Any help would be great. Here is the file:

Thanks, Jack

<%@ LANGUAGE="VBSCRIPT" %>
<% option explicit %>
<% Response.Buffer = True %>

<%
'*********************************************************** ************
'           ;           ;     COPYRIGHT NOTICE        
'   Code Example  :   Self Submitting "Contact Us" Form Using CDOSYS 
'   Author     :   Christopher Williams of        
'           ;        www.CJWSoft.com and www.PowerASP.com     
                   
' You can use this code anywhere as long as this copyright notice  
' remains with the code and the link to www.PowerASP.com remains on the 
' form page this code is used on         &nbs p;
'           ;         
'   (c) Copyright 2000 - 2005 by CJWSoft / PowerASP  All rights reserved
'*********************************************************** ************
%>

<%
'Declaring Variables
Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_E mail
Dim ContactUs_Subject,ContactUs_Body,Action,IsError
 
' Edit these 3 values accordingly
smtpserver = "mail.someserver.com"
youremail = "yourmemail@yourserver.com"
yourpassword = "yourpassword"
 
' Grabbing variables from the form post
ContactUs_Name = Request("ContactUs_Name")
ContactUs_Email = Request("ContactUs_Email")
ContactUs_Subject = Request("ContactUs_Subject")
ContactUs_Body = Request("ContactUs_Body")
Action = Request("Action")
 
' Used to check that the email entered is in a valid format
Function IsValidEmail(Email)
 Dim ValidFlag,BadFlag,atCount,atLoop,SpecialFlag,UserName,Domain Name,atChr,tAry1
 ValidFlag = False
  If (Email <> "") And (InStr(1, Email, "@") > 0) And (InStr(1, Email, ".") > 0) Then
   atCount = 0
   SpecialFlag = False
   For atLoop = 1 To Len(Email)
   atChr = Mid(Email, atLoop, 1)
    If atChr = "@" Then atCount = atCount + 1
    If (atChr >= Chr(32)) And (atChr <= Chr(44)) Then SpecialFlag = True
    If (atChr = Chr(47)) Or (atChr = Chr(96)) Or (atChr >= Chr(123)) Then SpecialFlag = True
    If (atChr >= Chr(58)) And (atChr <= Chr(63)) Then SpecialFlag = True
    If (atChr >= Chr(91)) And (atChr <= Chr(94)) Then SpecialFlag = True
   Next
   If (atCount = 1) And (SpecialFlag = False) Then
    BadFlag = False
    tAry1 = Split(Email, "@")
    UserName = tAry1(0)
    DomainName = tAry1(1)
   If (UserName = "") Or (DomainName = "") Then BadFlag = True
   If Mid(DomainName, 1, 1) = "." then BadFlag = True
   If Mid(DomainName, Len(DomainName), 1) = "." then BadFlag = True
    ValidFlag = True
   End If
  End If
  If BadFlag = True Then ValidFlag = False
  IsValidEmail = ValidFlag
End Function
%>

<html>

<head>
<title>Contact Us Form ( Powered By PowerASP.com )</title>
</head>

<body style="font-family: Arial; font-size: 12px">

<%
If Action = "SendEmail" Then
 
 ' Here we quickly check/validate the information entered
 ' These checks could easily be improved to look for more things
 If IsValidEmail(ContactUs_Email) = "False" Then
  IsError = "Yes"
  Response.Write("<font color=""red"">You did not enter a valid email address.</font><br>")
 End If
 
 If ContactUs_Name = "" Then
  IsError = "Yes"
  Response.Write("<font color=""red"">You did not enter a Name.</font><br>")
 End If
 
 If ContactUs_Subject = "" Then
 IsError = "Yes"
  Response.Write("<font color=""red"">You did not enter a Subject.</font><br>")
 End If
 
 If ContactUs_Body = "" Then
  IsError = "Yes"
  Response.Write("<font color=""red"">You did not enter a Body.</font><br>")
 End If
 
End If
 
' If there were no input errors and the action of the form is "SendEMail" we send the email off
If Action = "SendEmail" And IsError <> "Yes" Then
 
 Dim strBody
 
 ' Here we create a nice looking html body for the email
 strBody = strBody & "<font face=""Arial"">Contact Us Form submitted at " & Now() &  vbCrLf & "<br><br>"
 strBody = strBody & "From http://" & Request.ServerVariables("HTTP_HOST") &  vbCrLf & "<br>"
 strBody = strBody & "IP " & Request.ServerVariables("REMOTE_ADDR") & vbCrLf & "<br>"
 strBody = strBody & "Name" & " : " & " " & Replace(ContactUs_Name,vbCr,"<br>") & "<br>"
 strBody = strBody & "Email" & " : " & " " & Replace(ContactUs_Email,vbCr,"<br>") & "<br>"
 strBody = strBody & "Subject" & " : " & " " & Replace(ContactUs_Subject,vbCr,"<br>") & "<br>"
 strBody = strBody & "<br>" & Replace(ContactUs_Body,vbCr,"<br>") & "<br>"
 strBody = strBody & "</font>"
 
 Dim ObjSendMail
 Set ObjSendMail = CreateObject("CDO.Message")
    
 'This section provides the configuration information for the remote SMTP server.
    
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver
 ObjSendMail.Configuration.Fields.Item (" http://schemas.microsoft.com/cdo/configuration/smtpserverpor t") = 25
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
 ObjSendMail.Configuration.Fields.Item (" http://schemas.microsoft.com/cdo/configuration/smtpconnectio ntimeout") = 60
    
 ObjSendMail.Configuration.Fields.Item (" http://schemas.microsoft.com/cdo/configuration/smtpauthentic ate") = 1 'basic (clear-text) authentication
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = youremail
 ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = yourpassword
    
 ObjSendMail.Configuration.Fields.Update
    
 'End remote SMTP server configuration section==
    
 ObjSendMail.To = youremail
 ObjSendMail.Subject = ContactUs_Subject
 ObjSendMail.From = ContactUs_Email
    
 ' we are sending a html email.. simply switch the comments around to send a text email instead
 ObjSendMail.HTMLBody = strBody
 'ObjSendMail.TextBody = strBody
    
 ObjSendMail.Send
    
 Set ObjSendMail = Nothing
 
' change the success messages below to say or do whatever you like
' you could do a response.redirect or offer a hyperlink somewhere.. etc etc
%>
<font size="2">Your message as seen below has been sent. Thank You !!
<br><br>
<font color="blue">
<% =Replace(ContactUs_Body,vbCr,"<br>") %>
</font>
</font>
<% Else %>

<form action="contact_us.asp" method="POST">
<input type="hidden" name="Action" value="SendEmail">
<font size="2">Contact Us:</font>
<br><br>
 <table border="0" cellspacing="1">
  <tr>
   <td valign="top">
    Name:
   </td>
   <td colspan="2">
    <input type="text" name="ContactUs_Name" size="35" value="<% =ContactUs_Name %>">
   </td>
  </tr>
  <tr>
   <td valign="top">
    Email:
   </td>
   <td colspan="2">
    <input type="text" name="ContactUs_Email" size="35" value="<% =ContactUs_Email %>">
   </td>
  </tr>
  <tr>
   <td valign="top">
    Subject:
   </td>
   <td colspan="2">
    <input type="text" name="ContactUs_Subject" value="<% =ContactUs_Subject %>" size="35">
   </td>
  </tr>
  <tr>
   <td valign="top">
    Message:
   </td>
   <td valign="top">
    <textarea rows="10" name="ContactUs_Body" cols="40"><% =ContactUs_Body %></textarea>
   </td>
  </tr>
  <tr>
   <td valign="top">
    &nbsp;
   </td>
   <td colspan="2">
    <input type="submit" value="Send Message">
   </td>
  </tr>
 </table>
</form>

<% End If %>

<!-- The link below must not be removed -->
<p>Contact Us Form Code provided by
<a target="_blank" href="http://www.PowerASP.com">www.PowerASP.com</a></p>
<!-- The link above must not be removed -->

</body>

</html>

Back to Top View ka3wjz's Profile Search for other info by ka3wjz
 
cwilliams
Admin Group
Admin Group
Avatar

Joined: April/26/2004
Location: United States
Online Status: Offline
Info: 137
Added: April/25/2006 at 1:07pm | IP Logged Quote cwilliams

not without a sh*tload of work. you'd have to totaly redo the error handling somehow to take error messages back to the 1st form as well as re-populate fields that were filled in...

thats the whole point of a self submitting form.. its the cleanest and best way to code something like this

if you want a two page deal you would be better off starting from scratch
http://www.powerasp.com/content/new/sending_email_cdosys.asp



__________________


Chris Williams
http://www.PowerASP.com
Back to Top View cwilliams's Profile Search for other info by cwilliams
 
ka3wjz
Newbie
Newbie
Avatar

Joined: April/25/2006
Location: United States
Online Status: Offline
Info: 3
Added: April/25/2006 at 4:20pm | IP Logged Quote ka3wjz

Thanks for your input. I'm not very good at programing but would like to add CHAPTCHA to increase security. After reviewing the install steps for CHAPTCHA it look as though you need a form and a form processor. If CHAPTCHA can be added with out cutting up the self submitting form all the much better.

Thanks, Jack

Back to Top View ka3wjz's Profile Search for other info by ka3wjz
 
cwilliams
Admin Group
Admin Group
Avatar

Joined: April/26/2004
Location: United States
Online Status: Offline
Info: 137
Added: April/25/2006 at 5:47pm | IP Logged Quote cwilliams

Pretty sure it's spelled Captcha

Captcha can be self submitting and here is example asp code..

http://www.tipstricks.org/

__________________


Chris Williams
http://www.PowerASP.com
Back to Top View cwilliams's Profile Search for other info by cwilliams
 
ka3wjz
Newbie
Newbie
Avatar

Joined: April/25/2006
Location: United States
Online Status: Offline
Info: 3
Added: April/26/2006 at 6:22am | IP Logged Quote ka3wjz

Pardon the spelling I was typing in a hurry. Thank you very much for your input this helps me out very much.

Thanks,

Jack

Back to Top View ka3wjz's Profile Search for other info by ka3wjz
 

If you wish to make a comment to this info you must first login
If you are not already registered you must first register

  A d d  -  P o s tAdd P o s t
Printable version Printable version

Info Jump
You cannot add new info in this area
You cannot add to info in this area
You cannot delete your info in this area
You cannot edit your info in this area
You cannot create polls in this area
You cannot vote in polls in this area

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2024 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages ASP programs help tutorial tutorials routine routines jobs listserve mailinglist bulletin board bulletin boards programming snippet snippets CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspprotect.com, www.cjwsoft.com,www.aspclassifieds.com,www.aspphotogallery.com