aparker81

Coldfusion/JQuery

Mar 16th, 2011
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfsilent>
  2.     <cfif isDefined ("url.firstname")>
  3.         <cfset firstname = #url.firstname#>
  4.     </cfif>
  5.     <cfif isDefined ("url.lastname")>
  6.         <cfset lastname = #url.lastname#>
  7.     </cfif>
  8.     <cfif isDefined ("url.email")>
  9.         <cfset email = #url.email#>
  10.     </cfif>
  11.  
  12.     <cffunction name="makeRandomString" returntype="string" output="false">
  13.        <cfset var chars = "23456789ABCDEFGHJKMNPQRS">
  14.        <cfset var length = randRange(4,6)>
  15.        <cfset var result = "">
  16.        <cfset var i = "">
  17.        <cfset var char = "">
  18.        
  19.        <cfscript>
  20.            for(i=1; i <= length; i++) {
  21.               char = mid(chars, randRange(1, len(chars)),1);
  22.               result&=char;
  23.            }
  24.        </cfscript>
  25.          
  26.        <cfreturn result>
  27.     </cffunction>
  28.    
  29.    
  30.     <!--- Param FORM variables. --->
  31.     <cfparam name="URL.Reg" type="string" default=""/>
  32.     <cfparam name="FORM.affiliation" type="string" default=""/>
  33.     <cfparam name="FORM.status" type="string" default=""/>
  34.     <cfparam name="FORM.phone" type="string" default=""/>
  35.     <cfparam name="FORM.session" type="string" default="" />
  36.     <cfparam name="FORM.major" type="string" default="" />
  37.     <cfparam name="FORM.guests" type="string" default="" />
  38.     <cfparam name="FORM.plater3" type="string" default="" />
  39.     <cfparam name="FORM.plater4" type="string" default="" />
  40.     <cfparam name="FORM.plater5" type="string" default="" />
  41.     <cfparam name="FORM.plater6" type="string" default="" />   
  42.     <cfparam name="FORM.plater7" type="string" default="" />   
  43.     <cfparam name="FORM.jones" type="string" default="" />
  44.     <cfparam name="FORM.jones2" type="string" default="" />
  45.     <cfparam name="FORM.partner" type="string" default="" />   
  46.     <cfparam name="FORM.other" type="string" default="" /> 
  47.  
  48.     <cfparam name="FORM.sessionSymposium" default="no" />  
  49.     <cfparam name="FORM.sessionPresentPoster" default="no" />  
  50.     <cfparam name="FORM.sessionAttendPoster" default="no" />   
  51.     <cfparam name="FORM.sessionShowcase" default="no" />   
  52.  
  53.  
  54.  
  55.  
  56.    
  57.     <!---
  58.         For the form submission flag, since we are asking
  59.         it to be of type numeric, we have to catch the
  60.         CFParam in case someone has hacked the HTML and
  61.         altered the value being sent (a non-numeric value
  62.         will throw a ColdFusion error).
  63.     --->
  64.     <cftry>
  65.         <cfparam
  66.             name="FORM.submitted"
  67.             type="numeric"
  68.             default="0"
  69.             />
  70.  
  71.         <!--- Catch CFParam data type errors. --->
  72.         <cfcatch>
  73.             <cfset FORM.submitted = 0 />
  74.         </cfcatch>
  75.     </cftry>
  76.  
  77.     <!--- Define an array to catch the form errors. --->
  78.     <cfset arrErrors = ArrayNew( 1 ) />
  79.  
  80.     <!--- Check to see if the form has been submitted. --->
  81.     <cfif FORM.submitted>
  82.  
  83.         <!---
  84.             Now that the form has been submitted, we need
  85.             to validate the data.
  86.         --->
  87.        
  88.         <!--- Validate affiliation. --->
  89.         <cfif NOT Len( FORM.affiliation )>
  90.             <cfset ArrayAppend(
  91.                 arrErrors,
  92.                 "Please specify your affiliation."
  93.                 ) />
  94.         </cfif>
  95.  
  96.         <!---Validate School or Department if affiliation choice is status --->
  97.         <cfif form.affiliation eq 'status' and not len (form.status)>
  98.             <cfset ArrayAppend(
  99.                 arrErrors,
  100.                 "Please specify your school or department."
  101.                 ) />
  102.         </cfif>
  103.                
  104.         <!---Validate major if affiliation choice is plater--->
  105.         <cfif form.affiliation eq 'plater' and not len (form.major)>
  106.             <cfset ArrayAppend(
  107.                 arrErrors,
  108.                 "Please specify your major."
  109.                 ) />
  110.         </cfif>
  111.  
  112.     <!---Validate guests if affiliation choice is plater--->
  113.         <cfif form.affiliation eq 'plater' and not len (form.guests)>
  114.             <cfset ArrayAppend(
  115.                 arrErrors,
  116.                 "Please specify how many guests will accompany you."
  117.                 ) />
  118.         </cfif>
  119.  
  120.     <!---Validate guests if affiliation choice is plater--->
  121.         <cfif form.affiliation eq 'plater' and len (form.guests) and not len (form.plater3)>
  122.             <cfset ArrayAppend(
  123.                 arrErrors,
  124.                 "Please specify the guest name(s)."
  125.                 ) />
  126.         </cfif>
  127.  
  128.     <!---Validate major if affiliation choice is jones--->
  129.         <cfif form.affiliation eq 'jones' and not len(form.jones)>
  130.             <cfset ArrayAppend(
  131.                 arrErrors,
  132.                 "Please specify your major."
  133.                 ) />
  134.         </cfif>
  135.  
  136.     <!---Validate major if affiliation choice is jones--->
  137.         <cfif form.affiliation eq 'jones' and not len(form.jones2)>
  138.             <cfset ArrayAppend(
  139.                 arrErrors,
  140.                 "Please specify your scholarship name."
  141.                 ) />
  142.         </cfif>
  143.  
  144.     <!---Validate organization name if affiliation choice is partner--->
  145.         <cfif form.affiliation eq 'partner' and not len(form.partner)>
  146.             <cfset ArrayAppend(
  147.                 arrErrors,
  148.                 "Please specify your organization name."
  149.                 ) />
  150.         </cfif>
  151.  
  152.     <!---Validate otherif affiliation choice is other--->
  153.         <cfif form.affiliation eq 'other' and not len(form.other)>
  154.             <cfset ArrayAppend(
  155.                 arrErrors,
  156.                 "Please clarify ''other.''"
  157.                 ) />
  158.         </cfif>
  159.  
  160.  
  161.  
  162.         <!---Validate phone number--->
  163.         <cfif not Len(form.phone)>
  164.             <cfset ArrayAppend(
  165.                 arrErrors,
  166.                 "Please provide your phone number."
  167.                 ) />
  168.         </cfif>
  169.  
  170.         <!---Validate session--->
  171.         <cfif form.sessionSymposium NEQ 1 or form.sessionPresentPoster NEQ 1 or form.sessionAttendPoster NEQ 1 or form.sessionShowcase NEQ 1>
  172.             <cfset ArrayAppend(
  173.                 arrErrors,
  174.                 "Please specify at least one session."
  175.                 ) />
  176.         </cfif>
  177.  
  178.  
  179.            
  180.         <!---Validate CAPTCHA --->
  181.         <cfif hash(form.captcha) neq form.captchaHash>
  182.             <cfset ArrayAppend(
  183.                arrErrors,
  184.                "You did not enter the correct security text."
  185.                ) />
  186.         </cfif>        
  187.        
  188.         <!---
  189.             Now that we have validated our form data, let's
  190.             check to see if there are any form validation
  191.             errors. Only if there are no errors do w want to
  192.             continue processing the data - otherwise, we want
  193.             to skip this next part and let the form re-render.
  194.         --->
  195.         <cfif NOT ArrayLen( arrErrors )>
  196.  
  197.        
  198.  
  199.             <cfmail
  200.                 to="[email protected]"
  201.                 from="[email protected]"
  202.                 subject="Civic Engagement Showcase"
  203.                 type="html"
  204.                 failto="[email protected]"
  205.                 >
  206.                 <p>Hello,</p>
  207.                 <p>
  208.                     The following was submitted through the <a href="#CGI.HTTP_REFERER#"> web page</a> on
  209.                     #DateFormat( Now(), "mmm d, yyyy" )# at
  210.                     #TimeFormat( Now(), "h:mm TT" )#.
  211.                 </p>
  212.                
  213.                 <ul>
  214.                     <li>First Name: #firstname#</li>
  215.                     <li>Last Name: #lastname#</li>
  216.                     <li>Affiliation:  #form.affiliation#
  217.                         <cfif Len(form.status)>
  218.                             <ul>
  219.                                 <li>School or Department:  #form.status#</li>
  220.                             </ul>
  221.                         </cfif>                
  222.                     </li>
  223.                     <li>Phone Number:  #form.phone#</li>
  224.                     <li>Session: #form.session#</li>               
  225.                 </ul>
  226.            
  227.              
  228.             </cfmail>
  229.             <!---
  230.                 At this point, you would probably forward
  231.                 the user to another page using something
  232.                 like CFLocation.
  233.             --->
  234.  
  235.        
  236.         <cflocation url="#cgi.SCRIPT_NAME#?reg=y"> 
  237.  
  238.         </cfif>
  239.     </cfif>
  240.  
  241. </cfsilent>
  242.  
  243.  
  244. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  245. <html xmlns="http://www.w3.org/1999/xhtml">
  246. <head>
  247. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  248. <title>My Site</title>
  249. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
  250. <script src="../../assets/js/jquery.maskedInput-1.2.2.min.js" type="text/javascript"></script>
  251.  
  252. <script src="../../expand.js" type="text/javascript"></script>
  253.  
  254. <script type="text/javascript">
  255. jQuery(function($) {
  256.       $.mask.definitions['~']='[+-]';
  257.       $('#date').mask('99/99/9999');
  258.       $('#phone').mask('(999) 999-9999');
  259.    });
  260. </script>
  261.  
  262.     <script type="text/javascript">
  263.     $(function() {
  264.         //This hides all initial textboxes
  265.         $('label').hide();
  266.         $('#affiliation').change(function() {
  267.             //This saves some time by caching the jquery value
  268.             var val = $(this).val();
  269.             //this hides any boxes that the previous selection might have left open
  270.             $('label').hide();
  271.             //This just opens the ones we want based off the selection
  272.             switch (val) {
  273.             case 'status':
  274.                 $('#status').show();
  275.                 break;
  276.             case 'plater':
  277.                 $('#plater').show();
  278.                 $('#plater2').show();
  279.                 $('#plater3').show();
  280.                 $('#plater4').show();
  281.                 $('#plater5').show();
  282.                 $('#plater6').show();
  283.                 $('#plater7').show();
  284.                 break;
  285.             case 'jones':
  286.                 $('#jones').show();
  287.                 $('#jones2').show();
  288.                 break;
  289.             case 'partner':
  290.                 $('#partner').show();
  291.                 break;
  292.             case 'other':
  293.                 $('#other').show();
  294.                 break;
  295.                
  296.             }
  297.         });
  298.        
  299.     });
  300.    
  301.     </script>
  302.  
  303. <style>
  304. label{display:block;}
  305. </style>
  306. </head>
  307. <body>
  308.  
  309.         <div id="overall">
  310.             <cfif URL.Reg EQ "Y">
  311.                 <p>Thank you for your submission.  We have received your information.</p>
  312.             <cfelse>
  313.                 <cfoutput>
  314.                     <!--- Check to see if we have any form errors. --->
  315.                     <cfif ArrayLen( arrErrors )>
  316.                
  317.                         <h4>Please review the following:</h4>
  318.                
  319.                         <ul>
  320.                             <cfloop
  321.                                 index="intError"
  322.                                 from="1"
  323.                                 to="#ArrayLen( arrErrors )#"
  324.                                 step="1">
  325.                
  326.                                 <li>
  327.                                     <div class="required">#arrErrors[ intError ]#</div>
  328.                                 </li>
  329.                             </cfloop>
  330.                         </ul>
  331.                     </cfif>
  332.                 </cfoutput>
  333.    
  334.                 <cfoutput>
  335.                     <form
  336.                         action="#cgi.SCRIPT_NAME#?firstname=#firstname#&lastname=#lastname#&email=#email#"
  337.                         method="post"
  338.                         enctype="multipart/form-data">
  339.                                      
  340.                  <!--- Our form submission flag. --->
  341.                  <input type="hidden" name="submitted" value="1" />
  342.                     <h3>7<sup>th</sup> Annual Civic Engagement Showcase </h3>
  343.                       <p>Please fill out this page and click submit to complete registration.  For more information, <a href="mailto:[email protected]">contact Mansi Patel</a>.</p>
  344.                       <p>Fields marked <span class="required">&##8727;</span> are required.</p>
  345.                         <fieldset>
  346.                             <ol>  
  347.                                     <li><span class="required">&##8727;</span>Affiliation:
  348.                                     <select name="affiliation" id="affiliation">
  349.                                         <option value="">- Select Affiliation -</option>
  350.                                         <option value="status"<cfif Form.affiliation EQ 'status'> selected="selected"</cfif>>Faculty or Staff</option>
  351.                                         <option value="plater"<cfif form.affiliation eq 'plater'> selected="selected"</cfif>>Plater Medallion</option>
  352.                                         <option value="jones"<cfif form.affiliation eq 'jones'> selected="selected"</cfif>>Sam H. Jones Scholar</option>
  353.                                         <option value="partner"<cfif form.affiliation eq 'partner'> selected="selected"</cfif>>Community Partner</option>
  354.                                         <option value="other"<cfif form.affiliation eq 'other'> selected="selected"</cfif>>Other</option>
  355.                                     </select>
  356.                                     <br />
  357.                                     <label id="status" for="affiliation"><span class="required">&##8727;</span>Enter School or Department
  358.                                         <input type="text" id="status" name="status" value="#form.status#"/>
  359.                                     </label>
  360.                                     <label id="plater" for="plater"><span class="required">&##8727;</span>Enter Your Major
  361.                                         <input type="text" name="major" id="plater" value="#form.major#"/>
  362.                                     </label>
  363.                                     <label id="plater2" for="plater2">Select Number of Guests
  364.                                         <SELECT name="guests" id="guests">
  365.                                             <option value="">- Select Guests -</option>
  366.                                             <option value="1"<cfif form.guests EQ 1> selected="selected"></cfif>>1</option>
  367.                                             <option value="2"<cfif form.guests EQ 2> selected="selected"></cfif>>2</option>
  368.                                             <option value="3"<cfif form.guests EQ 3> selected="selected"></cfif>>3</option>
  369.                                             <option value="4"<cfif form.guests EQ 4> selected="selected"></cfif>>4</option>
  370.                                             <option value="5"<cfif form.guests EQ 5> selected="selected"></cfif>>5</option>
  371.                                         </SELECT>
  372.                                     </label>
  373.                                     <label id="plater3" for="plater3">Guest Name:<input type="text" id="plater3" name="plater3" value="#form.plater3#"/></label>
  374.                                     <label id="plater4" for="plater4">Guest Name:<input type="text" id="plater4" name="plater4" value="#form.plater4#"/></label>
  375.                                     <label id="plater5" for="plater5">Guest Name:<input type="text" id="plater5" name="plater5" value="#form.plater5#"/></label>
  376.                                     <label id="plater6" for="plater6">Guest Name:<input type="text" id="plater6" name="plater6" value="#form.plater6#"/></label>
  377.                                     <label id="plater7" for="plater7">Guest Name:<input type="text" id="plater7" name="plater7" value="#form.plater7#" /></label>
  378.                                        
  379.                                     <label id="jones" for="jones"><span class="required">&##8727;</span>Enter Major
  380.                                         <input type="text" id="jones" name="jones" value="#form.jones#"/>
  381.                                     </label>
  382.                                     <label id="jones2" for="jones2"><span class="required">&##8727;</span>Enter Scholarship Name
  383.                                         <input type="text" id="jones2" name="jones2" value="#form.jones2#"/>
  384.                                     </label>
  385.                                
  386.                                     <label id="partner" for="partner"><span class="required">&##8727;</span>Enter Organization Name
  387.                                         <input type="text" id="partner" name="partner" value="#form.partner#"/>
  388.                                     </label>
  389.                                     <label id="other" for="other"><span class="required">&##8727;</span>Other
  390.                                         <input type="text" id="other" name="other" value="#form.other#"/>
  391.                                     </label>
  392.                                 </li>
  393.                                 <br />
  394.                                 <br />
  395.                                 <li>
  396.                                     <span class="required">&##8727;</span>Phone Number:<input type="text" id="phone" name="phone" maxlength="14" value="#form.phone#">
  397.                                 </li>
  398.                                 <li>
  399.                                     Select one or more session(s):
  400.                                         <br>
  401.                                         <input type="checkbox" name="sessionSymposium" value="Symposium" <cfif isDefined("form.sessionSymposium") and form.sessionSymposium EQ '1'>checked="checked"</cfif> />Attend CE Symposium: 3:30-4:15 pm (CE 305/CE309)<br />
  402.                                         <input type="checkbox" name="sessionPresentPoster" value="presentPoster" <cfif isDefined("form.sessionPresentPoster") and form.sessionPresentPoster EQ '1'>checked="checked"</cfif> />Present Poster Presentation: for applications, visit CSL Conference Page<br />
  403.                                         <input type="checkbox" name="sessionAttendPoster" value="attendPoster" <cfif isDefined("form.sessionAttendPoster") and form.sessionAttendPoster EQ '1'>checked="checked"</cfif>/>Attend CE Poster Presentations: 4:00-4:45 pm and 5:45-6:30 pm (CE 450)<br />
  404.                                         <input type="checkbox" name="sessionShowcase" value="Showcase" <cfif isDefined("form.sessionShowcase") and form.sessionShowcase EQ '1'>checked="checked"</cfif>/>Attend CE Showcase Program: 4:45-6:30 pm (CE 450)<br />
  405.                                    
  406.                                    
  407.                                 </li>
  408.                                  
  409.                                 <li>
  410.                                     <span class="required">&##8727;</span>Enter Text Below (case-sensitive):</label>
  411.                                     <input id="captcha" name="captcha" class="text" type="text"/>
  412.                                 </li>
  413.                             </ol>
  414.                                 <cfset captcha = makeRandomString()>
  415.                                 <cfset captchaHash = hash(captcha)>
  416.                                     <input type="hidden" name="captchaHash" value="#captchaHash#">  
  417.                                 <cfimage action="captcha" width="300" height="55" text="#captcha#" fonts="verdana,arial" >  
  418.                             </fieldset>            
  419.                         <br />
  420.                        
  421.                     <cfif isDefined ("url.firstname")> 
  422.                         <input type="hidden"  name="firstname" value="<cfoutput>#url.firstname#</cfoutput>">
  423.                     </cfif>
  424.                     <cfif isDefined ("url.lastname")>
  425.                         <input type="hidden"  name="lastname" value="<cfoutput>#url.lastname#</cfoutput>">
  426.                     </cfif>
  427.                     <cfif isDefined ("url.email")>
  428.                         <input type="hidden"  name="email" value="<cfoutput>#url.email#</cfoutput>">
  429.                     </cfif>
  430.                         <input type="hidden" value="#Now()#" />
  431.                         <input type="submit" value="Submit"/>
  432.                 </form>
  433.    
  434.         </cfoutput>
  435.         </cfif>
  436.        
  437.    
  438. </body>
  439. </html>
Advertisement
Add Comment
Please, Sign In to add comment