Forked from stevewithington/mura-onBeforeFormSubmitSave-onFormSubmitErrorRender.cfm
Created
February 16, 2014 23:01
-
-
Save ronnieduke/9041900 to your computer and use it in GitHub Desktop.
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
<cfscript> | |
// Drop this in your Site or Theme eventHandler.cfc | |
public any function onBeforeFormSubmitSave($) { | |
// reference to the formBean | |
var formBean = arguments.$.event('formBean'); | |
// example on how to create some errors | |
var error = ''; | |
var errors = {}; | |
// Check for any required fields/attributes, and create an error if missing | |
if ( !Len($.event('message')) ) { | |
StructAppend(errors, {'error1': 'Message is required.'}); | |
} | |
// if ( !Len(newBean.getValue('someExtendedAttribute'))) { | |
// StructAppend(errors, {'error2': 'Some Extended Attribute is required.'}); | |
// } | |
// if there's errors | |
if ( !StructIsEmpty(errors) ) { | |
for ( error in errors ) { | |
formBean.getErrors()[error] = errors[error]; | |
} | |
arguments.$.event('acceptdata', false); | |
} else { | |
// no errors, so we're good! | |
// do whatever else you want to do here (e.g. log something, etc.) | |
} | |
} | |
public any function onFormSubmitErrorRender($) { | |
var str = ''; | |
var formBean = arguments.$.event('formBean'); | |
var error = ''; | |
var errors = {}; | |
savecontent variable='str' { | |
if ( !StructIsEmpty(formBean.getErrors()) ) { | |
WriteOutput('<div class="alert alert-danger"><p><strong>Please review the following error(s)</strong></p><ul>'); | |
errors = formBean.getErrors(); | |
for ( error in errors ) { | |
WriteOutput('<li>' & errors[error] & '</li>'); | |
} | |
WriteOutput('</ul></div><p><a href="javascript:history.go(-1);">Try again »</a></p>'); | |
} | |
} | |
return str; | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment