Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active September 22, 2017 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/fa355ab83b4fd9ddca7b18506256a90c to your computer and use it in GitHub Desktop.
Save Shelob9/fa355ab83b4fd9ddca7b18506256a90c to your computer and use it in GitHub Desktop.
Example code for caldera_forms_submit_start_processors action in Caldera Forms See: https://calderaforms.com/doc/caldera_forms_submit_start_processors/
<?php
/**
* Get all data from a form after field validation, before processors
*/
add_action( 'caldera_forms_submit_start_processors', function( $form ) {
//get submission data as field ID => value
$values = Caldera_Forms::get_submission_data( $form );
//convert to slug => value
$data = array();
foreach ( $values as $field_id => $value ){
//get field config
$field = Caldera_Forms_Field_Util::get_field( $field_id, $form );
if( $field ){
$data[ $field[ 'slug' ] ] = $value;
}
}
/** Now you can use $data to send a slack alert, email, push notification, etc. */
});
<?php
/**
* Trigger a zapier webhook before any processors run
*/
add_action( 'caldera_forms_submit_start_processors', function( $form ){
//stop if Zapier isn't active
if( ! function_exists( 'cf_zapier_push_trigger' ) ){
return;
}
//create a compatible config for processor
$config = array(
'url' => 'https://zapier.com/the-reset-of-your-webhook-url'
);
cf_zapier_push_trigger( $config, $form );
});
<?php
/**
* Send an extra email before processing your form
*/
add_action( 'caldera_forms_submit_start_processors', function( $form ) {
//get submission data as field ID => value
$values = Caldera_Forms::get_submission_data( $form );
//convert to slug => value
$data = array();
foreach ( $values as $field_id => $value ){
//get field config
$field = Caldera_Forms_Field_Util::get_field( $field_id, $form );
if( $field ){
$data[ $field[ 'slug' ] ] = $value;
}
}
/** Send the main mailer with a modifed subject line and recpient */
//get mailer settings
$settings = $form['mailer'];
//change subject
$settings[ 'subject' ] = 'New pending submission on form ' . $form[ 'name' ];
//change recipients of email
$settings[ 'recipients' ] = array( 'you@something.com', 'someone@something.com' );
//If you use {summary} magic tag for email, will need to parse it manually.
$summary_magic = new Caldera_Forms_Magic_Summary( $form, $values );
$summary_magic->set_html_mode( true );
$magic_tag = $summary_magic->get_tag();
$settings[ 'email_message' ] = $settings[ 'message' ] = str_replace( '{summary}', $magic_tag, $settings[ 'email_message' ] );
//End part for summary magic tag
//Send email
Caldera_Forms_Save_Final::do_mailer( $form, null, $data, $settings );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment