Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Created December 29, 2017 01:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/67d072a76016262703324e8524abc16c to your computer and use it in GitHub Desktop.
Save Shelob9/67d072a76016262703324e8524abc16c to your computer and use it in GitHub Desktop.
Run a callback function on Caldera Forms submit
jQuery( document ).on( 'cf.form.submit', function (event, data ) {
//data.$form is a jQuery object for the form that just submitted.
//log form id
console.log($form.data( 'form-id' ) );
//apply a css to form
$form.css( {
visibility: 'hidden',
display: 'none'
});
});
@ArbenHusic
Copy link

Hi,
I've been trying to find an answer with no luck. Maybe you can help.

This works great, but what I need is a function if the submission is successful.
For example, if the form is successfully submitted do this...

@yastrS
Copy link

yastrS commented Aug 29, 2019

Hi,
I've been trying to find an answer with no luck. Maybe you can help.

This works great, but what I need is a function if the submission is successful.
For example, if the form is successfully submitted do this...

Finaly i found - https://calderaforms.com/doc/custom-processing-of-caldera-forms-submissions/#custom-js

@danieliser
Copy link

@yastrS, @ArbenHusic - This is the way I came up with, bypassing the need to create a processor or hook in a custom JS function. We needed to do it programmatically via another plugin that was integrating with CF and a few other plugins.

After digging through the source I came up with a 2 step workaround. First, when a form is submitted its ID & $form object are stored in a block scope variable, then on verified successful complete via ajax we reuse that stored info anyway we need:

https://gist.github.com/danieliser/c3ac258cefce49b802a74856b081a94a

A bit hackish, but there is no event that is fired only on successful submission that still has reference to the form itself. Storing form references before AJAX submission was the only way to get around that for us and not require adding any new processors.

@TomLeogrande
Copy link

I have a similar issue I am trying to resolve.

Danieleliser, would have any thoughts on this you would be willing to share?

I have a Caldera Form that I do not want to save one of the fields on submission. I want to set a field - null either before submission or clear it from the database after submission.

Any thoughts on the best way to do this would be great.

Thanks,

@danieliser
Copy link

@TomLeogrande, not quite as familiar with the internal workings of the plugin as a whole. From just the surface, I'd say there has to be a server side PHP filter you could use to clean up that data pre-save.

Our use case was detecting ajax submissions inside a popup, so we could interact with the popups own API to close on submission, trigger a thank you popup, set cookies etc. So I never had to really mess with what happened with the submission server side, just needed to ensure it only processed our stuff when it was a true success.

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