Created
January 23, 2018 14:58
-
-
Save bowler865/018cc91cb069079cdb2905494ca6aa31 to your computer and use it in GitHub Desktop.
dspCustomForm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mura name="Custom Form" contenttypes="*"></mura> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfsilent> | |
<cfset formBean=m.getBean('content').loadBy(title='[TITLE OF YOUR FORM HERE -- FOR DATA COLLECTION]',type='Form')> | |
<cfset errors={}> | |
<cfset errorFields = ""> | |
<cfset doSave=false> | |
<cfif m.event('attemptSave') eq 'true'> | |
<cfset dataBean=m.getBean('dataCollectionBean').set(m.event().getAllValues())> | |
<cfset dataBean.setValue('formID',formBean.getContentID())> | |
<cfset errors=dataBean.validate(m).getErrors()> | |
// Check for any required fields/attributes, and create an error if missing | |
<cfif not Len($.event('txtName'))> | |
<cfset errors.name = 'Please enter your full name'> | |
<cfset errorFields = ListAppend(errorFields, "name", ",")> | |
</cfif> | |
<cfif not Len($.event('txtEmail'))> | |
<cfset errors.Email = "Please provide your email address."> | |
<cfset ErrorFields = ListAppend(ErrorFields, "email", ",")> | |
</cfif> | |
<cfif not Len($.event('txtSubject'))> | |
<cfset errors.subject = 'Please enter your subject.'> | |
<cfset errorFields = ListAppend(errorFields, "subject", ",")> | |
</cfif> | |
<cfif not Len($.event('txtMessage'))> | |
<cfset errors.message = 'Please enter a message.'> | |
<cfset errorFields = ListAppend(errorFields, "message", ",")> | |
</cfif> | |
<cfif StructIsEmpty(errors)> | |
<cfset doSave=true> | |
</cfif> | |
</cfif> | |
</cfsilent> | |
<cfoutput> | |
<cfif doSave> | |
<cfset dataBean.save()> | |
<p> | |
Thank you for your request. We'll get back to you right away.</p> | |
<cfmail to="#formBean.get('ResponseSendTo')#" from="[email protected]" replyto="#$.event('txtEmail')#" subject="[Your subject here]" type="html" server="" username="" password=""> | |
<html> | |
<body> | |
<h2>Form Submission</h2> | |
<p><strong>Name:</strong> #$.event('txtName')#<br> | |
<strong>Email:</strong> #$.event('txtEmail')#</p> | |
<p><strong>Message:</strong><br> | |
#$.event('txtMessage')#</p> | |
</body> | |
</html> | |
</cfmail> | |
<cfelse> | |
<cfif not StructIsEmpty(errors)> | |
<div class="alert alert-danger" role="alert" style="margin-bottom:15px;"> | |
#m.getBean('utility').displayErrors(errors)# | |
<strong>We were unable to process your request because some required fields were left blank. Please fix the errors shown below.</strong> | |
</div> | |
</cfif> | |
<style> | |
form .headline{margin-bottom:10px;} | |
</style> | |
<form class="form-horizontal"> | |
<div class="row"> | |
<div class="col-xs-12"> | |
<div class="form-group<cfif listfindnocase(errorFields,'name')> has-error</cfif>"><label class="col-xs-4 col-md-3 col-lg-2">Name*</label> | |
<div class="col-xs-8 col-md-9 col-lg-10"> | |
<input class="form-control" id="txtName" name="txtName" type="text" value="#esapiEncode('html_attr',m.event('txtName'))#" /> | |
<cfif listfindnocase(errorFields,"name",",")><span id="helpBlock" class="help-block">#Errors.name#</span></cfif> | |
</div> | |
</div> | |
<div class="form-group<cfif listfindnocase(errorFields,'Email')> has-error</cfif>"><label class="col-xs-4 col-md-3 col-lg-2">Email Address*</label> | |
<div class="col-xs-8 col-md-9 col-lg-10"> | |
<input class="form-control" id="txtEmail" name="txtEmail" type="text" value="#esapiEncode('html_attr',m.event('txtEmail'))#" /> | |
<cfif listfindnocase(errorFields,"Email",",")><span id="helpBlock" class="help-block">#Errors.Email#</span></cfif> | |
</div> | |
</div> | |
<div class="form-group<cfif listfindnocase(errorFields,'subject')> has-error</cfif>"><label class="col-xs-4 col-md-3 col-lg-2">Subject*</label> | |
<div class="col-xs-8 col-md-9 col-lg-10"> | |
<input class="form-control" id="txtSubject" name="txtSubject" type="text" value="#esapiEncode('html_attr',m.event('txtSubject'))#" /> | |
<cfif listfindnocase(errorFields,"subject",",")><span id="helpBlock" class="help-block">#Errors.subject#</span></cfif> | |
</div> | |
</div> | |
<div class="form-group<cfif listfindnocase(errorFields,'message')> has-error</cfif>"><label class="col-xs-4 col-md-3 col-lg-2">Message*</label> | |
<div class="col-xs-8 col-md-9 col-lg-10"> | |
<textarea class="form-control" rows="3" id="txtMessage" name="txtMessage">#esapiEncode('html_attr',m.event('txtMessage'))#</textarea> | |
<cfif listfindnocase(errorFields,"message",",")><span id="helpBlock" class="help-block">#Errors.message#</span></cfif> | |
</div> | |
</div> | |
<div class="col-xs-12"> | |
<div class="form-group"> | |
<div class="col-xs-12"> | |
#m.dspObject_Include(thefile='datacollection/dsp_form_protect.cfm')# | |
</div> | |
</div> | |
<div class="form-group"> | |
<div class="col-xs-4 col-md-3 col-lg-2"></div> | |
<div class="col-xs-8 col-md-9 col-lg-10"> | |
<input class="btn btn-primary btn-block" id="btnSend" name="btnSend" type="submit" value="Send" /> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!--- Add a few custom values ---> | |
<input type="hidden" name="linkservid" value="#m.content('contentid')#"> | |
<input type="hidden" name="siteid" value="#m.event('siteid')#"> | |
<input type="hidden" name="formid" value="#formBean.getContentID()#"> | |
<input type="hidden" name="attemptSave" value="true"> | |
#m.renderCSRFTokens(format="form",context=formBean.getContentID())# | |
</form> | |
</cfif> | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment