Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!---If the http is not secure, make it secure--->
- <cfif not cgi.server_port_secure>
- <cflocation url="https://#cgi.server_name##cgi.script_name#?#cgi.query_string#" addtoken="no" />
- </cfif>
- <cfsilent>
- <cffunction name="uploadFile">
- <cfargument name="formField" hint="Form field name that holds the file to be uploaded" required="yes">
- <cfargument name="renameTo" hint="What to rename the file, ex: 01_nominationLetter" required="yes">
- <cfargument name="uploadErrorMessage" required="no" default="Error uploading file"/>
- <cfargument name="allowedExtensions" required="no" default="doc,docx,pdf,txt,rtf">
- <cfargument name="extensionErrorMessage" required="no" default="Only doc, docx, pdf, txt, and rtf file formats are accepted">
- <cfset var dir = expandPath("./nominationUploads/#trim(form.fname)#_#trim(form.lname)#_#trim(form.uid)#/")>
- <cfparam name="request.filesUploaded" default="#arrayNew(1)#">
- <cftry>
- <cffile action="upload" filefield="#arguments.formField#" nameconflict="makeunique" destination="#dir#">
- <cfcatch type="any"><cfset ArrayAppend(arrErrors, arguments.uploadErrorMessage )></cfcatch>
- </cftry>
- <cfif not listFindNoCase(arguments.allowedExtensions, cffile.ServerFileExt)>
- <cfset ArrayAppend(arrErrors, arguments.extensionErrorMessage )>
- </cfif>
- <cffile action="rename" destination="#dir##renameTo#.#cffile.ServerFileExt#" source="#dir##cffile.serverFile#" >
- <cfset ArrayAppend(request.filesUploaded, dir & arguments.renameTo & "." & cffile.ServerFileExt )>
- </cffunction>
- <cffunction name="removeFilesOnError">
- <cfloop from="1" to="#arrayLen(request.filesUploaded)#" index="i">
- <cftry><cffile action="delete" file="#request.filesUploaded[i]#"/><cfcatch type="any"></cfcatch></cftry>
- </cfloop>
- </cffunction>
- <!--- Param FORM variables. --->
- <cfparam name="URL.Reg" type="string" default="" />
- <cfparam name="FORM.fname" type="string" default="" />
- <cfparam name="FORM.lName" type="string" default="" />
- <cfparam name="FORM.uid" type="string" default="" />
- <cfparam name="FORM.classification" type="string" default="" />
- <cfparam name="FORM.school" type="string" default="" />
- <cfparam name="FORM.department" type="string" default="" />
- <cfparam name="FORM.address1" type="string" default="" />
- <cfparam name="FORM.address2" type="string" default="" />
- <cfparam name="FORM.email" type="string" default="" />
- <cfparam name="FORM.phone" type="string" default="" />
- <cfparam name="FORM.NOMfname" type="string" default="" />
- <cfparam name="FORM.NOMlname" type="string" default="" />
- <cfparam name="FORM.NOMuid" type="string" default="" />
- <cfparam name="FORM.NOMschool" type="string" default="" />
- <cfparam name="FORM.NOMdepartment" type="string" default="" />
- <cfparam name="FORM.NOMaddress1" type="string" default="" />
- <cfparam name="FORM.NOMaddress2" type="string" default="" />
- <cfparam name="FORM.NOMemail" type="string" default="" />
- <cfparam name="FORM.NOMphone" type="string" default="" />
- <cfparam name="FORM.nominationLetter" type="string" default="" />
- <cfparam name="FORM.curriculumVita" type="string" default="" />
- <cfparam name="FORM.captcha" type="string" default="" />
- <!---
- For the form submission flag, since we are asking
- it to be of type numeric, we have to catch the
- CFParam in case someone has hacked the HTML and
- altered the value being sent (a non-numeric value
- will throw a ColdFusion error).
- --->
- <cftry>
- <cfparam
- name="FORM.submitted"
- type="numeric"
- default="0"
- />
- <!--- Catch CFParam data type errors. --->
- <cfcatch>
- <cfset FORM.submitted = 0 />
- </cfcatch>
- </cftry>
- <!--- Define an array to catch the form errors. --->
- <cfset arrErrors = ArrayNew( 1 ) />
- <!--- Check to see if the form has been submitted. --->
- <cfif FORM.submitted>
- <!---Now that the form has been submitted, we need to validate the data.--->
- <!--- Validate nominee's first name. --->
- <cfif NOT Len( FORM.fname )>
- <cfset ArrayAppend(
- arrErrors,
- "Please enter nominee's first name."
- ) />
- </cfif>
- <!--- Validate nominee's last name. --->
- <cfif NOT Len( FORM.lname )>
- <cfset ArrayAppend(
- arrErrors,
- "Please enter nominee's last name."
- ) />
- </cfif>
- <!--- Validate nominee's university id. --->
- <cfif NOT Len( FORM.uid )>
- <cfset ArrayAppend(
- arrErrors,
- "Please enter nominee's ten digit University ID."
- ) />
- </cfif>
- <cfset uploadFile('myFileField', 'renameToThis' )>
- <cfset uploadFile('myFileField2', 'renameToThat' , 'My custom upload error!')>
- <cfset uploadFile('anotherFile', 'differentName', 'Another custom upload msg!', 'doc,docx', 'This one only lets you upload word docs!')>
- <cfif arrayLen( arrErrors ) >
- <cfset removeFilesOnError()>
- </cfif>
- <!---Validate CAPTCHA --->
- <cfif form.captcha neq session.captcha>
- <cfset ArrayAppend(
- arrErrors,
- "You did not enter the correct security text."
- ) />
- <!---
- Now that we have validated our form data, let's
- check to see if there are any form validation
- errors. Only if there are no errors do w want to
- continue processing the data - otherwise, we want
- to skip this next part and let the form re-render.
- --->--->
- <cfelseif NOT ArrayLen( arrErrors )>
- <cfmail
- to="[email protected]"
- from="[email protected]"
- subject="Alvin S. Bynum Mentor Award"
- type="html"
- failto="[email protected]"
- >
- <p>Hello,</p>
- <p>
- The following nomination has been
- submitted through the <a href="#CGI.HTTP_REFERER#">Alvin S. Bynum Mentor Award web site</a> on
- #DateFormat( Now(), "mmm d, yyyy" )# at
- #TimeFormat( Now(), "h:mm TT" )#.
- </p>
- <h3>Nominee Details</h3>
- <ul>
- <li>First Name: #form.fname#</li>
- <li>Last Name: #form.lname#</li>
- </ul>
- <h3>Document Details</h3>
- <ul>
- <li>Nomination Letter: #clientNominationLetter#</li>
- <li>Curriculum Vita: #clientCurriculumVita#</li>
- </ul>
- <br />
- <p>Thank you</p>
- </cfmail>
- <!---
- At this point, you would probably forward
- the user to another page using something
- like CFLocation.
- --->
- <cflocation url="#cgi.SCRIPT_NAME#?reg=y" addtoken="no">
- </cfif>
- </cfif>
- </cfsilent>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
- <script>
- $(document).ready(function() {
- $("#captchaDiv").load("showcaptcha.cfm");
- $("#reloadLink").click(function(e) {
- $("#captchaDiv").load("showcaptcha.cfm");
- e.preventDefault();
- });
- })
- </script>
- </head>
- <cfoutput>
- <!--- Check to see if we have any form errors. --->
- <cfif ArrayLen( arrErrors )>
- <p class="attention">
- Please review the following:
- </p>
- <ul class="attention">
- <cfloop
- index="intError"
- from="1"
- to="#ArrayLen( arrErrors )#"
- step="1">
- <li>
- #arrErrors[ intError ]#
- </li>
- </cfloop>
- </ul>
- </cfif>
- <cfif URL.Reg EQ "Y">
- <p class="attention">Thank you for submitting your profile information.</p>
- <cfelse>
- <form
- action="#cgi.SCRIPT_NAME#"
- method="post"
- enctype="multipart/form-data">
- <!--- Our form submission flag. --->
- <input type="hidden" name="submitted" value="1" />
- <p>Fields marked <span class="required">&##8727;</span> are required.</p>
- <fieldset>
- <legend>Nominee Information</legend>
- <div class="notes">
- <h4>Eligibility</h4>
- <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>
- </div>
- <ol>
- <li>
- <label for="first name"><span class="required">*</span>First Name:</label>
- <input name="fname" type="text" maxlength="25" value="#form.fname#"/>
- </li>
- <li>
- <label for="last name"><span class="required">*</span>Last Name:</label>
- <input name="lname" type="text" maxlength="25" value="#form.lname#" />
- </li>
- <li>
- <label for="university id"><span class="required">*</span>University ID:</label>
- <input name="uid" type="text" maxlength="10" value="#form.uid#"/>
- </li>
- </ol>
- </fieldset>
- <fieldset>
- <ol>
- <li>
- <label for="nomination-letter"><span class="required">*</span>Nomination Letter:</label>
- <input type="file" name="nominationLetter" />
- </li>
- <li>
- <label for="curriculum-vita"><span class="required">*</span>Curriculum Vita:</label>
- <input type="file" name="curriculumVita" />
- </li>
- <li>
- <label for="recommendation"><span class="required">*</span>Recommendation Letter 1:</label>
- <input type="file" name="recommendation" tabindex="22">
- </li>
- <li>
- <label for="security"><span class="required">*</span>Enter Text Below (case-sensitive):</label>
- <input id="captcha" name="captcha" type="text" />
- </li>
- <div id="captchaDiv"></div>
- Can't read? <a href="" id="reloadLink">Reload</a>
- </ol>
- </fieldset>
- <br />
- <input type="hidden" value="#Now()#" />
- <input type="submit" value="Submit" />
- </form>
- </cfif>
- </cfoutput>
- <div class="request"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment