Skip to content

Instantly share code, notes, and snippets.

@howellcc
Last active January 20, 2016 19:10
Show Gist options
  • Save howellcc/3c16b480e69b094acb6b to your computer and use it in GitHub Desktop.
Save howellcc/3c16b480e69b094acb6b to your computer and use it in GitHub Desktop.
[MuraCMS] Confirmation email for a form builder form.
//Place this code in your theme-leve eventHandler.cfc.
public any function onAfterFormSubmitSave($) output="true"{
if(len($.event('CONFIRMATIONEMAIL')) and isValid('email',$.event('CONFIRMATIONEMAIL'))) {
local.formFields = deserializeJSON($.event('formbean').getbody()).form.fields;
local.mailSvc = new mail();
local.mailSvc.setTo($.event('CONFIRMATIONEMAIL'))
.setFrom("[email protected]")
.setSubject("My important subject")
.setType("html");
local.mailBody = "<html><body>
<p>Put your confirmation text here. </p>
<h3>Fieldset Label</h3>
<table>
<tr><td>#getFieldLabel(formFields,'field1Name')#</td><td>#$.event('field1Name')#</td></tr>
<tr><td>#getFieldLabel(formFields,'field2Name')#</td><td>#$.event('field2Name')#</td></tr>
</table>
</body></html>";
local.mailSvc.send(body=local.mailBody);
}
}
private string function getFieldLabel(required any formFields, required string fieldName){
for(local.thisFieldID in structKeyList(formfields)){
if(lcase(formFields[local.thisFieldID].name) eq lcase(fieldName))
return formFields[local.thisFieldID].label;
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment