aparker81

CF Contact Form

Mar 25th, 2011
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfsilent>
  2.  
  3. <cffunction name="makeRandomString" returntype="string" output="false">
  4.    <cfset var chars = "23456789ABCDEFGHJKMNPQRS">
  5.    <cfset var length = randRange(4,6)>
  6.    <cfset var result = "">
  7.    <cfset var i = "">
  8.    <cfset var char = "">
  9.    
  10.    <cfscript>
  11.    for(i=1; i <= length; i++) {
  12.      char = mid(chars, randRange(1, len(chars)),1);
  13.      result&=char;
  14.   }
  15.   </cfscript>
  16.      
  17.   <cfreturn result>
  18. </cffunction>
  19.    
  20.     <!--- Param FORM variables. --->
  21.     <cfparam
  22.         name="URL.Reg"
  23.        type="string"
  24.        default=""
  25.        />
  26.  
  27.  
  28.     <cfparam
  29.         name="FORM.firstname"
  30.         type="string"
  31.         default=""
  32.         />
  33.  
  34.  
  35.     <cfparam
  36.         name="FORM.lastname"
  37.         type="string"
  38.         default=""
  39.         />
  40.  
  41.  
  42.     <cfparam
  43.         name="FORM.email"
  44.         type="string"
  45.         default=""
  46.         />
  47.  
  48.     <cfparam
  49.         name="FORM.phone"
  50.         type="string"
  51.         default=""
  52.         />
  53.  
  54.     <cfparam
  55.         name="FORM.topic"
  56.         type="string"
  57.         default=""
  58.         />
  59.  
  60.     <cfparam
  61.         name="FORM.requestedTime"
  62.         type="string"
  63.         default=""
  64.         />
  65.  
  66.     <cfparam
  67.         name="FORM.alternateTime"
  68.         type="string"
  69.         default=""
  70.         />
  71.    
  72.  
  73.  
  74.  
  75.     <!---
  76.         For the form submission flag, since we are asking
  77.         it to be of type numeric, we have to catch the
  78.         CFParam in case someone has hacked the HTML and
  79.         altered the value being sent (a non-numeric value
  80.         will throw a ColdFusion error).
  81.     --->
  82.     <cftry>
  83.         <cfparam
  84.             name="FORM.submitted"
  85.             type="numeric"
  86.             default="0"
  87.             />
  88.  
  89.         <!--- Catch CFParam data type errors. --->
  90.         <cfcatch>
  91.             <cfset FORM.submitted = 0 />
  92.         </cfcatch>
  93.     </cftry>
  94.  
  95.  
  96.     <!--- Define an array to catch the form errors. --->
  97.     <cfset arrErrors = ArrayNew( 1 ) />
  98.  
  99.  
  100.     <!--- Check to see if the form has been submitted. --->
  101.     <cfif FORM.submitted>
  102.  
  103.         <!---
  104.             Now that the form has been submitted, we need
  105.             to validate the data.
  106.         --->
  107.        
  108.  
  109.         <!--- Validate first name. --->
  110.         <cfif NOT Len( FORM.firstname )>
  111.             <cfset ArrayAppend(
  112.                 arrErrors,
  113.                 "Please enter your first name."
  114.                 ) />
  115.         </cfif>
  116.         <!--- Validate last name. --->
  117.         <cfif NOT Len( FORM.lastname )>
  118.             <cfset ArrayAppend(
  119.                 arrErrors,
  120.                 "Please enter your last name."
  121.                 ) />
  122.         </cfif>
  123.  
  124.         <!--- Validate email address. --->
  125.         <cfif not len(trim(form.email)) or not isValid("email", form.email)>
  126.             <cfset ArrayAppend(
  127.                 arrErrors,
  128.                 "Please enter your email address."
  129.                 ) />
  130.         </cfif>
  131.  
  132.         <!---Validate CAPTCHA --->
  133.         <cfif hash(form.captcha) neq form.captchaHash>
  134.             <cfset ArrayAppend(
  135.                arrErrors,
  136.                "You did not enter the right security text."
  137.                ) />
  138.         </cfif>
  139.  
  140.        
  141.  
  142.         <!---
  143.             Now that we have validated our form data, let's
  144.             check to see if there are any form validation
  145.             errors. Only if there are no errors do w want to
  146.             continue processing the data - otherwise, we want
  147.             to skip this next part and let the form re-render.
  148.         --->
  149.         <cfif NOT ArrayLen( arrErrors )>
  150.  
  151.            
  152.  
  153.  
  154.             <cfmail
  155.            
  156.                 to="myemail"
  157.                 cc="#form.email#"
  158.                 from="myemail"
  159.                 subject="Online Consultation Request Form"
  160.                 type="html"
  161.                 failto="myemail"
  162.                 >
  163.                 <p>Hello,</p>
  164.                 <p>
  165.                     The following application has been
  166.                     submitted through the <a href="#CGI.HTTP_REFERER#">Online Consultation Request Form</a> on
  167.                     #DateFormat( Now(), "mmm d, yyyy" )# at
  168.                     #TimeFormat( Now(), "h:mm TT" )#.
  169.                 </p>
  170.                
  171.                
  172.                 <h3>Contact Details</h3>
  173.                 <ul>
  174.                     <li>First Name: #form.firstname#</li>
  175.                     <li>Last Name:  #form.lastname#</li>
  176.                     <li>Email:  #form.email#</li>
  177.                     <cfif len("form.phone") NEQ ""><li>Phone:  #form.phone#</li></cfif>
  178.                     <cfif len("form.topic") NEQ ""><li>Topic:  #form.topic#</li></cfif>
  179.                     <cfif len("form.requestedTime") NEQ ""><li>Requested Time:  #form.requestedTime#</li></cfif>
  180.                     <cfif len("form.alternateTime") NEQ ""><li>Alternate Time:  #form.alternateTime#</li></cfif>
  181.                 </ul>
  182.                 <br />
  183.                 <br />
  184.                 <br />
  185.                 <p>Thank you,<br />
  186.                 CLS Web</p>
  187.            
  188.             <!---
  189.                 At this point, you would probably forward
  190.                 the user to another page using something
  191.                 like CFLocation.
  192.             --->
  193.  
  194.             </cfmail>
  195.            
  196.             <cflocation url="#cgi.SCRIPT_NAME#?reg=y">
  197.            
  198.         </cfif>
  199.  
  200.     </cfif>
  201.  
  202. </cfsilent>
  203.  
  204. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  205. <html xmlns="http://www.w3.org/1999/xhtml">
  206. <head>
  207. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  208. <title>Consultations</title>
  209.  
  210.  
  211.     <link rel="icon" href="http://www.iupui.edu/favicon.ico" type="image/x-icon" />
  212.     <link rel="shortcut icon" href="http://www.iupui.edu/favicon.ico" type="image/x-icon" />
  213.  
  214.  
  215. <link href="../css/global.css" rel="stylesheet" type="text/css" />
  216. <link href="../css/menu5.css" rel="stylesheet" type="text/css" />
  217. <link href="../css/crossColumn.css" rel="stylesheet" type="text/css" />
  218. <script src="../expand.js" type="text/javascript"></script>
  219. <script type="text/javascript">
  220.  
  221.  
  222. </head>
  223.  
  224. <body>
  225.  
  226.     <div id="header">
  227.         <cfinclude template="/includes/Header.html">
  228.     </div>
  229.  
  230.     <div id="holderWhite">  
  231.         <cfinclude template="/includes/Header.html">
  232.  
  233.  
  234.  
  235.   <div id="leftMainPage"> <h2>Consultations </h2>
  236.    <cfinclude template="../includes/leftLinksConsults.htm">
  237. <!---
  238.  
  239.     <h2 class="relatedHeader">Related Resources  
  240.    </h2>
  241.     <div class="supportRes">
  242.      
  243.      
  244.     </div>
  245.     <h2>Teaching Tips</h2>
  246.     <cfinclude template="../includes/teachTip.htm">
  247.     --->
  248.     <h2>For More Information</h2>
  249.     <div class="contact">
  250.      
  251.       <p>Contact</p>
  252.     </div>
  253.   </div>
  254.   <div id="rightMainPage">
  255.    
  256.     <div id="overall">
  257.       <img src="../images/consults.jpg" width="615" height="189" />
  258.         <cfif URL.Reg EQ "Y">
  259.             <p>Thank you for submitting your inquiry</p>       
  260.         <cfelse>
  261.  
  262.      
  263.        
  264.       <h1>Greeting</h1>
  265.       <cfoutput>
  266.         <cfif ArrayLen( arrErrors )>
  267.    
  268.             <h4>Please review the following:</h4>
  269.    
  270.             <ul>
  271.                 <cfloop
  272.                     index="intError"
  273.                     from="1"
  274.                     to="#ArrayLen( arrErrors )#"
  275.                     step="1">
  276.    
  277.                     <li>
  278.                         <div class="required">#arrErrors[ intError ]#</div>
  279.                     </li>
  280.                 </cfloop>
  281.             </ul>
  282.         </cfif>  
  283.      
  284. <form
  285.              action="#cgi.SCRIPT_NAME#"
  286.              method="post"
  287.              enctype="multipart/form-data">
  288.              
  289.              <!--- Our form submission flag. --->
  290.              <input type="hidden" name="submitted" value="1" />   <table width="74%" border="0" cellpadding="2" cellspacing="2">
  291.         <tr>
  292.           <td width="32%"><div align="right">First Name:</div></td>
  293.           <td width="68%"><label for="textfield"></label>
  294.           <input type="text" name="firstName" value="#form.firstname#"/></td>
  295.         </tr>
  296.         <tr>
  297.           <td><div align="right">Last Name:</div></td>
  298.           <td><input type="text" name="lastName" value="#form.lastname#"/></td>
  299.         </tr>
  300.         <tr>
  301.           <td><div align="right">Email:</div></td>
  302.           <td><input type="text" name="email" value="#form.email#" /></td>
  303.         </tr>
  304.         <tr>
  305.           <td><div align="right">Phone:</div></td>
  306.           <td><input type="text" name="phone" value="#form.phone#"/></td>
  307.         </tr>
  308.         <tr>
  309.           <td><div align="right">Topic/Comments:</div></td>
  310.           <td><label for="textarea"></label>
  311.           <textarea name="topic" cols="35" value="#form.topic#"></textarea></td>
  312.         </tr>
  313.         <tr>
  314.           <td><div align="right">Requested Time: </div></td>
  315.           <td><input type="text" name="requestedTime" value="#form.requestedTime#" /></td>
  316.         </tr>
  317.         <tr>
  318.           <td><div align="right">Alternate Time: </div></td>
  319.           <td><input type="text" name="alternateTime" value="#form.alternateTime#" /></td>
  320.         </tr>
  321.         <tr>
  322.           <td><label for="Submit"></label><div align="center">Fill in the words below: </div></td>
  323.           <td><label for="textfield"></label></td>
  324.         </tr>
  325.         <tr>
  326.             <td><label for="security">Enter Text Below (case-sensitive):</label>
  327.             <td><input id="captcha" name="captcha" class="text" type="text" tabindex="20"/></td>
  328.         </tr>
  329.         <tr>
  330.             <cfset captcha = makeRandomString()>
  331.             <cfset captchaHash = hash(captcha)>
  332.           <td><input type="hidden" name="captchaHash" value="#captchaHash#"></td>
  333.           <td><cfimage action="captcha" width="300" height="55" text="#captcha#" fonts="verdana,arial" > </td>
  334.         </tr>
  335.         <tr>
  336.           <td>&nbsp;</td>
  337.           <td><input type="hidden" value="#Now()#" />
  338.               <input type="submit" value="Submit Inquiry"  tabindex="21"/>
  339.          </td>
  340.         </tr>
  341.       </table>
  342.      
  343.       </form>
  344. </cfoutput>
  345. </cfif>
  346.      
  347.      
  348.      
  349.      
  350.      
  351.      
  352.      
  353.      
  354.      
  355.      
  356.     </div>
  357.   </div>
  358.   <div class="clear"></div>
  359. </div>
  360.  
  361. </body>
  362. </html>
Advertisement
Add Comment
Please, Sign In to add comment