Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active April 27, 2018 19:20
Show Gist options
  • Save stevewithington/f7da3c6273274e121124 to your computer and use it in GitHub Desktop.
Save stevewithington/f7da3c6273274e121124 to your computer and use it in GitHub Desktop.
Mura CMS : Announce an Event From a Form
<!--- 1) Create a form with a hidden form field like shown below, and place it in a layout template, or in a display object, etc. --->
<form method="post">
<input type="text" name="myField" value="Some Value">
<input type="hidden" name="myFormIsSubmitted" value="true">
<input type="submit">
</form>
<cfscript>
// 2) In the eventHandler.cfc (Site, Theme, Plugin, or other custom handler) you could listen for the even in one of Mura's eventHandlers such as 'onRenderStart'
public any function onRenderStart(event, m){
if ( arguments.event.get('myFormIsSubmitted') == 'true' ){
arguments.m.announceEvent('CustomFormSubmitted');
}
}
// 3) In the eventHandler.cfc (Site, Theme, Plugin, or other custom handler) you could then have your custom event
public any function onCustomFormSubmitted(event, m) {
// do something here
WriteDump(var=arguments.event.get('myField), abort=true);
// OR, WriteDump(var=arguments.event.getAllValues(), abort=true);
}
</cfscript>
@charlesr1971
Copy link

Steve. For some reason my 'onRenderStart' inside my eventHandlers -> plugin.cfc directory, fires 2 times per request and my custom form handler, fires 4 times per request? Any ideas? Thanks...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment