Required a file upload as part of a form

Community Beginner ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

 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?

Views

69

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

This answer is going to be kind of vague, as I don't have a copy of CF in front of me to test things out. But presumably you're using CFINPUT for this, and CFINPUT has a lot of attributes. It does have a "required" attribute, and that may work all by itself ... but maybe not. As an alternative, you can use a Javascript validation function that will let you cancel the submission of the form, and call that with the "onvalidate" attribute. There are plenty of non-CF resources that will show you how to validate that a file has been selected, I hope.

 

Dave Watts, Eidolon LLC

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

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>

 

Some notes:

  1. the form page applicantUploader.cfm is the same as the form's action-page
  2. there is a cffile tag for each file-upload field
  3. the value of the destination attribute is the directory C:\uploads
  4. "makeUnique" instructs ColdFusion not to delete or overwrite a previously uploaded file. If the uploaded file is called myResume.doc, and there exists a previously uploaded file of the same name (that is C:\uploads\myResume.doc), ColdFusion will store the new upload as C:\uploads\myResume1.doc. The next myResume.doc upload will be stored as C:\uploads\myResume2.doc, and so on.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 30, 2021 May 30, 2021

Copy link to clipboard

Copied

LATEST

Hi mrhodes@HM ,

Problem solved?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines