The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
kelley
Posted by: Adam | August 5, 2009 @ 10:00am
ColdFusion Code
[
Download
]
<!--- Kill extra output. ---> <cfsilent> <!--- Param FORM variables. ---> <cfparam name="FORM.eventType" type="string" default="" /> <cfparam name="FORM.location" type="string" default="" /> <cfparam name="FORM.date" type="string" default="" /> <cfparam name="FORM.deadline" type="string" default="" /> <cfparam name="FORM.description" type="string" default="" /> <cfparam name="FORM.website" type="string" default="" /> <cfparam name="FORM.name" type="string" default="" /> <cfparam name="FORM.email" type="string" default="" /> <cfparam name="FORM.altName" type="string" default="" /> <cfparam name="FORM.altEmail" type="string" default="" /> <cfparam name="FORM.flyer" 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. ---> <cfif NOT Len( FORM.eventType )> <cfset ArrayAppend( arrErrors, "Please select the event type." ) /> </cfif> <!--- Validate location. ---> <cfif NOT Len( FORM.location )> <cfset ArrayAppend( arrErrors, "Please enter event location." ) /> </cfif> <!--- Validate date. ---> <cfif NOT Len( FORM.date )> <cfset ArrayAppend( arrErrors, "Please enter event date." ) /> </cfif> <!--- Validate deadline. ---> <cfif NOT Len( FORM.deadline )> <cfset ArrayAppend( arrErrors, "Please enter event deadline." ) /> </cfif> <!--- Validate description. ---> <cfif NOT Len( FORM.description )> <cfset ArrayAppend( arrErrors, "Please enter event description" ) /> </cfif> <!--- Validate name. ---> <cfif NOT Len( FORM.name )> <cfset ArrayAppend( arrErrors, "Please enter contact name." ) /> </cfif> </cfif> <!--- Validate email. ---> <cfif NOT IsValid( "email", FORM.email )> <cfset ArrayAppend( arrErrors, "Please enter a valid email address" ) /> </cfif> <!--- Validate alt contact name. ---> <cfif NOT Len( FORM.altName )> <cfset ArrayAppend( arrErrors, "Please enter an alternate contact name" ) /> </cfif> <!--- Validate altemail. ---> <cfif NOT IsValid( "email", FORM.altEmail )> <cfset ArrayAppend( arrErrors, "Please enter a valid alternate contact email address" ) /> </cfif> <!--- When it comes to validating the resume, we want to check to see if they selected one. Then, once they selected one, we ONLY want to mess with it if there are no errors caused by other form fields. ---> <cfif NOT Len( FORM.flyer )> <cfset ArrayAppend( arrErrors, "Please select a file to upload" ) /> <cfelseif ArrayLen( arrErrors )> <!--- The file has been selected, but there are errors caused by other parts of the form validation. Therefore, we now have a file that is just sitting in our temp folder. Delete this file to keep a clean server. ---> <cftry> <cffile action="DELETE" file="#FORM.flyer#" /> <cfcatch> <!--- File delete error. ---> </cfcatch> </cftry> <cfelse> <!--- The resume has been selected and there are no other errors caused by Form validation. Therefore, we can now deal with the file upload. There is a chance that the file upload will cause an error, so be sure to wrap all file actions in CFTry / CFCatch blocks. ---> <cftry> <cffile action="UPLOAD" filefield="flyer" destination="#GetTempDirectory()#" nameconflict="MAKEUNIQUE" /> <!--- Now that we have the file uploaded, let's check the file extension. I find this to be better than checking the MIME type as that can be inaccurate (so can this, but at least it doesn't throw a ColdFusion error). ---> <cfif NOT ListFindNoCase( "pdf,doc,jpg,gif,rtf", CFFILE.ServerFileExt )> <cfset ArrayAppend( arrErrors, "Only PDF, DOC, JPG, GIF and RTF file formats are accepted" ) /> <!--- Since this was not an acceptable file, let's delete the one that was uploaded. ---> <cftry> <cffile action="DELETE" file="#CFFILE.ServerDirectory#\#CFFILE.ServerFile#" /> <cfcatch> <!--- File Delete Error. ---> </cfcatch> </cftry> </cfif> <!--- Catch any file errors. ---> <cfcatch> <!--- There was some sort of error with the file upload. Set the error and then try to delete the file. ---> <cfset ArrayAppend( arrErrors, "There was a problem uploading your file" ) /> <!--- Try to delete the file. Again, we want to use CFTry / CFCatch whenever dealing with files, especially if we don't know if the file is even at the given path. ---> <cftry> <cffile action="DELETE" file="#CFFILE.ServerDirectory#\#CFFILE.ServerFile#" /> <cfcatch> <!--- File delete errors. ---> </cfcatch> </cftry> </cfcatch> </cftry> </cfif> <!--- 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. ---> <cfif NOT ArrayLen( arrErrors )> <!--- Create a short hand for the file. ---> <cfset strFilePath = ( CFFILE.ServerDirectory & "\" & CFFILE.ServerFile ) /> <cfmail to="jegsmith@iupui.edu" from="#FORM.email#" subject="Bizbeat Event Submission" type="html"> <p> The following file has been submitted through the web site on #DateFormat( Now(), "mmm d, yyyy" )# at #TimeFormat( Now(), "h:mm TT" )#. </p> <p>Event Type: #FORM.eventType#</p> <p>Location: #FORM.Location#</p> <p>Event Date: #FORM.Date#</p> <p>Deadline: #FORM.Deadline#</p> <p>Description: #FORM.description#</p> <p>website: #FORM.website#</p> <p>Contact Name: #FORM.Name#</p> <p>Contact Email: #FORM.Email#</p> <p>Alternate Contact Name: #FORM.altName#</p> <p>Alternate Contact Email: #FORM.altEmail#</p> <p>Flyer or Graphic: <em>See attached file</em></p> <!--- Attach the file. ---> <cfmailparam file="#strFilePath#" /> </cfmail> <!--- Delete the resume file since we no longer need it on the server. HOWEVER, this will only work if the emails are NOT getting spooled. If the email is getting spooled, then we will end up deleting the file before it had a chance to get attached to the outgoing email and the mail will end up failing after it leaves ColdFusion. *** Put back in ONLY if SpoolEnable="no" in your CFMail tag. ---> <!--- <cftry> <cffile action="DELETE" file="#strFilePath#" /> <cfcatch></cfcatch> </cftry> ---> <!--- At this point, you would probably forward the user to another page using something like CFLocation. ---> </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"><!-- InstanceBegin template="/Templates/iupui_global.dwt.cfm" codeOutsideHTMLIsLocked="false" --> <head> <!-- InstanceBeginEditable name="Meta Data" --> <title>Prospective Students: Admissions: Undergraduate Programs:Kelley School of Business: IUPUI Indianapolis</title> <meta name="Keywords" content="about, us, Kelley, School, of, Business, IU, Indiana, Purdue, University, Indianapolis, IUPUI" /> <meta name="Description" content="Description goes here." /> <!-- InstanceEndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="IU Office of Creative Services, iuweb @ indiana.edu" /> <link rel="icon" href="http://www.indiana.edu/favicon.ico" /> <link rel="shortcut icon" href="http://www.indiana.edu/favicon.ico" /> <style type="text/css" media="screen"> <!-- @import url("../../global/css/global.css"); @import url("../../global/css/tier.css"); @import url("../../global/css/widgets.css"); @import url("../../css/styles.css"); --> </style> <link href="../../global/css/print.css" rel="stylesheet" type="text/css" media="print" /> <script src="../../js/breadcrumbs.js" type="text/javascript"></script> <script src="../../global/js/spamspan.js" type="text/javascript"></script> <script src="../../global/js/swfobject.js" type="text/javascript"></script> <script src="/js/includes.js" type="text/javascript"></script> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-3947246-1"; urchinTracker(); </script> <!-- InstanceBeginEditable name="Page-Specific Items" --> <!-- InstanceEndEditable --> <!-- InstanceParam name="Navigation Location" type="URL" value="../../ssi/_nav.html" --><!-- InstanceParam name="Notables" type="boolean" value="true" --><!-- InstanceParam name="Widgets" type="boolean" value="true" --><!-- InstanceParam name="Section ID" type="text" value="undergrad" --><!-- InstanceParam name="Header Location" type="URL" value="../../ssi/_header.html" --><!-- InstanceParam name="Breadcrumb Location" type="URL" value="../../ssi/_breadcrumb.html" --><!-- InstanceParam name="Local Styles Location" type="URL" value="../../css/styles.css" --> </head> <body id="undergrad"> <!-- BEGIN SKIP NAVIGATION ANCHORS --> <div id="skipnav"> <p>Skip to: <a href="#search">search</a>, <a href="#links">navigation</a>, or <a href="#body">content</a>.</p> <hr /> </div> <!-- END SKIP NAVIGATION ANCHORS --> <cfinclude template="../../global/ssi/_branding.html"> <cfinclude template="../../ssi/_header.html"> <div id="wrapper"> <div id="shadow"> <div id="shadow_left"></div> <div id="main"> <div id="column"> <a name="links" id="links"></a> <div id="nav"> <cfinclude template="../../ssi/_nav.html"> </div> <!-- InstanceBeginEditable name="Notable" --> <!-- InstanceEndEditable --> </div> <div id="content_wrap"> <a name="body" id="body"></a> <div id="toolbar"> <cfinclude template="../../ssi/_breadcrumb.html"> </div> <div id="title"> <h2><!-- InstanceBeginEditable name="Page Title" -->Undergraduate Programs<!-- InstanceEndEditable --></h2> </div> <!-- BEGIN WIDGET COLUMN --> <div id="widget_column"> <!-- InstanceBeginRepeat name="Widgets" --><!-- InstanceBeginRepeatEntry --> <div class="widget"> <!-- InstanceBeginEditable name="Widget Content" --> <!-- BEGIN SPOTLIGHT --> <!-- END SPOTLIGHT --> <!-- InstanceEndEditable --> </div> <!-- InstanceEndRepeatEntry --><!-- InstanceEndRepeat --> </div> <!-- END WIDGET COLUMN --> <!-- BEGIN CONTENT --> <div id="content"> <!-- InstanceBeginEditable name="Content" --> <cfoutput> <!--- Check to see if we have any form errors. ---> <cfif ArrayLen( arrErrors )> <h3> Please review the following: </h3> <ul> <cfloop index="intError" from="1" to="#ArrayLen( arrErrors )#" step="1"> <li> #arrErrors[ intError ]# </li> </cfloop> </ul> </cfif> <form action="#CGI.script_name#" method="post" enctype="multipart/form-data"> <!--- Our form submission flag. ---> <table class="tbl_rankings" border="0" cellpadding="0" cellspacing="3"> <input type="hidden" name="submitted" value="1" /> <tr> <td>Event Type:</td><td><select name="eventType" value="#FORM.eventType#"> <option value="">--select event type--</option> <option value="Financial">Financial</option> <option value="Academic">Academic</option> <option value="Leadership">Leadership</option> <option value="Involvement">Involvement</option> <option value="Fun">Fun</option> </select> </td> </tr> <tr> <td>Event Location:</td><td><input type="text" name="location" value="#FORM.location#"/></td> </tr> <tr> <td>Event Date:</td><td><input type="text" name="date" value="#FORM.date#"/></td> </tr> <tr> <td>Event Deadline:</td><td><input type="text" name="deadline" value="#FORM.deadline#"/></td> </tr> <tr> <td>Event Description:</td><td><textarea name="description" rows="10" value="#FORM.description#"></textarea></td> </tr> <tr> <td>Website:</td><td><input type="text" name="website" value="#FORM.website#"/></td> </tr> <tr> <td>Contact Name:</td><td><input type="text" name="Name" value="#FORM.name#"/></td> </tr> <tr> <td>Contact Email:</td><td><input type="text" name="email" value="#FORM.email#"/></td> </tr> <tr> <td>Alternate Contact Name:</td><td><input type="text" name="altName"value="#FORM.altName#"/></td> </tr> <tr> <td>Alternate Contact Email:</td><td><input type="text" name="altEmail" value="#FORM.altEmail#"/></td> </tr> <tr> <td>Flyer or Graphic Upload: <br /><p class="caption">PDF, RTF, JPG, GIF or DOC</p></td><td><input type="file" name="flyer" id="flyer" value="#FORM.flyer#"/></td> </tr> <tr><td><input type="submit" value="Submit Application" /></td></tr> </table> </form> </cfoutput> <!-- InstanceEndEditable --> </div> <!-- END CONTENT --> </div> </div> <div id="shadow_right"></div> <div class="clear"></div> </div> </div> <cfinclude template="../../global/ssi/_footer.html"> </body> <!-- InstanceEnd --></html>
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.45 / 8
76 Votes
http://codebin.yi.org/342
page generated in 0.01 seconds