I work for a non-profit school and use ColdFusion for some of our custom web app stuff needs. I am defintiely no expert in coldfusion coding. I would like to create a form we can send applicants to so they can select the position they want to apply for, provide some basic contact information, and upload their resume and optionally a separate cover letter if it is not already part of the resume. I have been asked to make the resume a requirement to submit the form and I cannot figure out how to make a file upload on a form a requirement - is this possible? Can you point me in the right direction for accomplishing this?
Dave Watts, Eidolon LLC
Let's assume you're on Windows. Create the directory C:\uploads. Uploaded files will go in there.
Save the following code as applicantUploader.cfm anywhere under the webroot. Play with it and see whether it is the kind of thing you're looking for.
<cfif isDefined("Form.fieldnames") > <cftry> <cffile action = "upload" fileField = "resume" destination = "c:\uploads" nameConflict = "makeunique"> <cffile action = "upload" fileField = "coverLetter" destination = "c:\uploads" nameConflict = "makeunique"> <cfif cffile.FileWasSaved>Thanks for uploading your details, resume and cover-letter.</cfif> <cfcatch type="any"> <!--- There was an error. Display your custom message (Optional)---> <cfif cfcatch.message contains "The form field coverLetter did not contain a file"> Thanks for uploading your details and resume.<br> <span style="color:purple"><strong>Attention:</strong></span> You did not upload a separate cover-letter.<br><br> <cfelse> <span style="color:red"><strong>Attention:</strong></span> <cfoutput>#cfcatch.message#</cfoutput><br><br> </cfif> <!--- A user-friendly thing to do: take user back to upload form page ---> <a href="applicantUploader.cfm" title="Upload">Go back to the page for uploading Resume and Cover-letter</a> </cfcatch> </cftry> <cfelse> <cfoutput><form method="post" action="#cgi.script_name#" enctype="multipart/form-data"></cfoutput> <!--- First name:<input type="text" name="fname"><br> Middle name:<input type="text" name="mname"><br> Last name:<input type="text" name="lname"><br><br> E-mail:<input type="text" name="email"><br> Telephone number:<input type="text" name="phone"><br><br> Position you are applying for:<input type="text" name="position"><br><br> ---> Please select your Resume for upload (<strong>required</strong>):<br> <input name="resume" type="file" required><br><br> Please upload your Cover-letter for upload (optional):<br> <input name="coverLetter" type="file"> <br><br> <input name="submit" type="submit" value="Send"> </form> </cfif>