aparker81

UploadByNate

Jul 22nd, 2011
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!---If the http is not secure, make it secure--->
  2. <cfif not cgi.server_port_secure>
  3.    <cflocation url="https://#cgi.server_name##cgi.script_name#?#cgi.query_string#" addtoken="no" />
  4. </cfif>
  5.  
  6. <cfsilent>
  7.  
  8. <cffunction name="uploadFile">
  9.     <cfargument name="formField" hint="Form field name that holds the file to be uploaded" required="yes">
  10.     <cfargument name="renameTo" hint="What to rename the file, ex: 01_nominationLetter" required="yes">
  11.     <cfargument name="uploadErrorMessage" required="no" default="Error uploading file"/>
  12.     <cfargument name="allowedExtensions" required="no" default="doc,docx,pdf,txt,rtf">
  13.     <cfargument name="extensionErrorMessage" required="no" default="Only doc, docx, pdf, txt, and rtf file formats are accepted">
  14.     <cfset var dir = expandPath("./nominationUploads/#trim(form.fname)#_#trim(form.lname)#_#trim(form.uid)#/")>
  15.     <cfparam name="request.filesUploaded" default="#arrayNew(1)#">
  16.     <cftry>
  17.         <cffile action="upload" filefield="#arguments.formField#" nameconflict="makeunique" destination="#dir#">
  18.         <cfcatch type="any"><cfset ArrayAppend(arrErrors, arguments.uploadErrorMessage )></cfcatch>
  19.     </cftry>
  20.     <cfif not listFindNoCase(arguments.allowedExtensions, cffile.ServerFileExt)>
  21.         <cfset ArrayAppend(arrErrors, arguments.extensionErrorMessage )>
  22.     </cfif>
  23.     <cffile action="rename" destination="#dir##renameTo#.#cffile.ServerFileExt#" source="#dir##cffile.serverFile#" >
  24.     <cfset ArrayAppend(request.filesUploaded, dir & arguments.renameTo & "." & cffile.ServerFileExt )>
  25. </cffunction>
  26.  
  27. <cffunction name="removeFilesOnError">
  28.     <cfloop from="1" to="#arrayLen(request.filesUploaded)#" index="i">
  29.         <cftry><cffile action="delete" file="#request.filesUploaded[i]#"/><cfcatch type="any"></cfcatch></cftry>
  30.     </cfloop>
  31. </cffunction>
  32.  
  33.     <!--- Param FORM variables. --->
  34.     <cfparam name="URL.Reg" type="string" default="" />
  35.     <cfparam name="FORM.fname" type="string" default="" />
  36.     <cfparam name="FORM.lName" type="string" default="" />
  37.     <cfparam name="FORM.uid" type="string" default="" />
  38.     <cfparam name="FORM.classification" type="string" default="" />
  39.     <cfparam name="FORM.school" type="string" default="" />
  40.     <cfparam name="FORM.department" type="string" default="" />
  41.     <cfparam name="FORM.address1" type="string" default="" />
  42.     <cfparam name="FORM.address2" type="string" default="" />
  43.     <cfparam name="FORM.email" type="string" default="" />
  44.     <cfparam name="FORM.phone" type="string" default="" />
  45.     <cfparam name="FORM.NOMfname" type="string" default="" />
  46.     <cfparam name="FORM.NOMlname" type="string" default="" />
  47.     <cfparam name="FORM.NOMuid" type="string" default="" />
  48.     <cfparam name="FORM.NOMschool" type="string" default="" />
  49.     <cfparam name="FORM.NOMdepartment" type="string" default="" />
  50.     <cfparam name="FORM.NOMaddress1" type="string" default="" />
  51.     <cfparam name="FORM.NOMaddress2" type="string" default="" />
  52.     <cfparam name="FORM.NOMemail" type="string" default="" />
  53.     <cfparam name="FORM.NOMphone" type="string" default="" />
  54.  
  55.     <cfparam name="FORM.nominationLetter" type="string" default="" />
  56.     <cfparam name="FORM.curriculumVita" type="string" default="" />
  57.    
  58.    
  59.    
  60.     <cfparam name="FORM.captcha" type="string" default="" />
  61.    
  62.     <!---
  63.         For the form submission flag, since we are asking
  64.         it to be of type numeric, we have to catch the
  65.         CFParam in case someone has hacked the HTML and
  66.         altered the value being sent (a non-numeric value
  67.         will throw a ColdFusion error).
  68.     --->
  69.     <cftry>
  70.         <cfparam
  71.             name="FORM.submitted"
  72.             type="numeric"
  73.             default="0"
  74.             />
  75.  
  76.         <!--- Catch CFParam data type errors. --->
  77.         <cfcatch>
  78.             <cfset FORM.submitted = 0 />
  79.         </cfcatch>
  80.     </cftry>
  81.  
  82.  
  83.     <!--- Define an array to catch the form errors. --->
  84.     <cfset arrErrors = ArrayNew( 1 ) />
  85.  
  86.  
  87.     <!--- Check to see if the form has been submitted. --->
  88.     <cfif FORM.submitted>
  89.  
  90.         <!---Now that the form has been submitted, we need to validate the data.--->
  91.  
  92.         <!--- Validate nominee's first name. --->
  93.         <cfif NOT Len( FORM.fname )>
  94.             <cfset ArrayAppend(
  95.                 arrErrors,
  96.                 "Please enter nominee's first name."
  97.                 ) />
  98.         </cfif>
  99.        
  100.         <!--- Validate nominee's last name. --->
  101.         <cfif NOT Len( FORM.lname )>
  102.             <cfset ArrayAppend(
  103.                 arrErrors,
  104.                 "Please enter nominee's last name."
  105.                 ) />
  106.         </cfif>
  107.        
  108.         <!--- Validate nominee's university id. --->
  109.         <cfif NOT Len( FORM.uid )>
  110.             <cfset ArrayAppend(
  111.                 arrErrors,
  112.                 "Please enter nominee's ten digit University ID."
  113.                 ) />
  114.         </cfif>
  115.  
  116.         <cfset uploadFile('myFileField',  'renameToThis'  )>
  117.         <cfset uploadFile('myFileField2', 'renameToThat' , 'My custom upload error!')>
  118.         <cfset uploadFile('anotherFile',  'differentName', 'Another custom upload msg!', 'doc,docx', 'This one only lets you upload word docs!')>
  119.        
  120.         <cfif arrayLen( arrErrors ) >
  121.             <cfset removeFilesOnError()>
  122.         </cfif>
  123.  
  124.         <!---Validate CAPTCHA --->
  125.         <cfif form.captcha neq session.captcha>
  126.             <cfset ArrayAppend(
  127.                arrErrors,
  128.                "You did not enter the correct security text."
  129.                ) />
  130.        
  131.    
  132.        
  133.  
  134.  
  135.         <!---
  136.             Now that we have validated our form data, let's
  137.             check to see if there are any form validation
  138.             errors. Only if there are no errors do w want to
  139.             continue processing the data - otherwise, we want
  140.             to skip this next part and let the form re-render.
  141.         --->--->
  142.         <cfelseif  NOT ArrayLen( arrErrors )>
  143.  
  144.            
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.                 <cfmail
  157.                     to="[email protected]"
  158.                     from="[email protected]"
  159.                     subject="Alvin S. Bynum Mentor Award"
  160.                     type="html"
  161.                     failto="[email protected]"
  162.                 >
  163.                 <p>Hello,</p>
  164.                 <p>
  165.                     The following nomination has been
  166.                     submitted through the <a href="#CGI.HTTP_REFERER#">Alvin S. Bynum Mentor Award web site</a> on
  167.                     #DateFormat( Now(), "mmm d, yyyy" )# at
  168.                     #TimeFormat( Now(), "h:mm TT" )#.
  169.                 </p>
  170.                
  171.                 <h3>Nominee Details</h3>
  172.                 <ul>
  173.                     <li>First Name: #form.fname#</li>
  174.                     <li>Last Name:  #form.lname#</li>
  175.                    
  176.                 </ul>
  177.                
  178.                 <h3>Document Details</h3>
  179.                 <ul>
  180.                     <li>Nomination Letter:  #clientNominationLetter#</li>
  181.                     <li>Curriculum Vita:  #clientCurriculumVita#</li>
  182.                    
  183.                 </ul>
  184.                 <br />
  185.                    
  186.                 <p>Thank you</p>
  187.            
  188.        
  189.             </cfmail>
  190.  
  191.  
  192.  
  193.  
  194.             <!---
  195.                 At this point, you would probably forward
  196.                 the user to another page using something
  197.                 like CFLocation.
  198.             --->
  199.             <cflocation url="#cgi.SCRIPT_NAME#?reg=y" addtoken="no">
  200.         </cfif>
  201.  
  202.     </cfif>
  203.  
  204. </cfsilent>
  205.  
  206. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  207. <html xmlns="http://www.w3.org/1999/xhtml">
  208. <head>
  209. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  210. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  211.  
  212. <script>
  213. $(document).ready(function() {
  214.     $("#captchaDiv").load("showcaptcha.cfm");  
  215.    
  216.     $("#reloadLink").click(function(e) {
  217.         $("#captchaDiv").load("showcaptcha.cfm");          
  218.         e.preventDefault();
  219.     });
  220. })
  221. </script>
  222. </head>
  223.             <cfoutput>
  224.  
  225.         <!--- Check to see if we have any form errors. --->
  226.         <cfif ArrayLen( arrErrors )>
  227.  
  228.             <p class="attention">
  229.                 Please review the following:
  230.             </p>
  231.  
  232.             <ul class="attention">
  233.                 <cfloop
  234.                     index="intError"
  235.                     from="1"
  236.                     to="#ArrayLen( arrErrors )#"
  237.                     step="1">
  238.  
  239.                     <li>
  240.                         #arrErrors[ intError ]#
  241.                     </li>
  242.  
  243.                 </cfloop>
  244.             </ul>
  245.  
  246.         </cfif>
  247.  
  248.        
  249.     <cfif URL.Reg EQ "Y">
  250.         <p class="attention">Thank you for submitting your profile information.</p>
  251.     <cfelse>
  252.        
  253.              <form
  254.              action="#cgi.SCRIPT_NAME#"
  255.              method="post"
  256.              enctype="multipart/form-data">
  257.              
  258.              <!--- Our form submission flag. --->
  259.              <input type="hidden" name="submitted" value="1" />
  260.               <p>Fields marked <span class="required">&##8727;</span> are required.</p>
  261.              
  262.                
  263.              
  264.                 <fieldset>  
  265.                     <legend>Nominee  Information</legend>
  266.                         <div class="notes">
  267.                             <h4>Eligibility</h4>
  268.                                 <p class="last">Those eligible include full- and part-time faculty and academic  professional staff, including all advisors, mentors, and counselors at the TE,  PA, and PB employee classifications.</p>
  269.                 </div>
  270.                         <ol>  
  271.                             <li>  
  272.                                 <label for="first name"><span class="required">*</span>First Name:</label>  
  273.                                     <input name="fname" type="text" maxlength="25" value="#form.fname#"/>  
  274.                             </li>  
  275.                             <li>
  276.                                 <label for="last name"><span class="required">*</span>Last Name:</label>  
  277.                                     <input name="lname" type="text" maxlength="25" value="#form.lname#" />  
  278.                             </li>
  279.                             <li>
  280.                                 <label for="university id"><span class="required">*</span>University ID:</label>  
  281.                                     <input  name="uid" type="text" maxlength="10" value="#form.uid#"/>  
  282.                             </li>
  283.  
  284.                             </ol>  
  285.                 </fieldset>
  286.                
  287.                
  288.                
  289.                 <fieldset>
  290.                     <ol>
  291.                         <li>
  292.                             <label for="nomination-letter"><span class="required">*</span>Nomination Letter:</label>  
  293.                                 <input  type="file" name="nominationLetter" />  
  294.                         </li>
  295.                         <li>
  296.                             <label for="curriculum-vita"><span class="required">*</span>Curriculum Vita:</label>
  297.                                 <input type="file" name="curriculumVita" />
  298.                         </li>
  299.                         <li>
  300.                             <label for="recommendation"><span class="required">*</span>Recommendation Letter 1:</label>
  301.                                 <input type="file" name="recommendation" tabindex="22">
  302.                         </li>
  303.                        
  304.                         <li>
  305.                             <label for="security"><span class="required">*</span>Enter Text Below (case-sensitive):</label>
  306.                                 <input id="captcha" name="captcha" type="text" />
  307.                         </li>
  308.                        
  309.                             <div id="captchaDiv"></div>
  310.                             Can't read? <a href="" id="reloadLink">Reload</a>                          
  311.                     </ol>
  312.                
  313.                
  314.                 </fieldset>
  315.                                                                                                            
  316.                     <br />
  317.                     <input type="hidden" value="#Now()#" />
  318.                     <input type="submit" value="Submit" />
  319.             </form>
  320.                  </cfif>    
  321.         </cfoutput>
  322.  
  323.       <div class="request"></div>
  324. </body>
  325. </html>
Advertisement
Add Comment
Please, Sign In to add comment