Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active May 12, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Shelob9/213cf04a0ad506a20a5003ed66db48d3 to your computer and use it in GitHub Desktop.
Save Shelob9/213cf04a0ad506a20a5003ed66db48d3 to your computer and use it in GitHub Desktop.
Custom Processing of Caldera Forms Submissions code examples. See: https://calderaforms.com/doc/custom-processing-of-caldera-forms-submissions/
<?php
/**
* Gather all data from Caldera Forms submission as PHP array
*/
add_action( 'caldera_forms_submit_complete', 'slug_process_form', 55 );
function slug_process_form( $form ) {
//put form field data into an array $data
$data= array();
foreach( $form[ 'fields' ] as $field_id => $field){
$data[ $field['slug'] ] = Caldera_Forms::get_field_data( $field_id, $form );
}
//get embedded post ID.
$embeded_post_id = absint( $_POST[ '_cf_cr_pst' ] );
/** DO SOMETHING WITH $data here **/
}
<script>
//For this to work, must set "slug_post_form_submit" as the custom callback function in form settings
function slug_post_form_submit( obj ) {
if ( "complete" == obj.status ) {
new_order = {
order_id: obj.data.cf_id,
total: obj.data.total,
user_id: obj.data.user_id
};
/** Do something with new_order **/
}
}
</script>
<?php
/**
* Example action and callback function to use with Caldera Forms Run Action
*
* Upadate specific post meta from Caldera Forms submission
*/
add_action( 'my_text_action', 'my_test_function');
function my_test_function( $data ) {
if ( isset( $data[ 'field_id_with_meta_value' ] ) && isset( $data[ 'field_with_post_id' ] ) && 0 < absint( $data[ 'field_with_post_id' ] ) ) {
update_post_meta( $data[ 'field_with_post_id' ], 'meta_key_name', strip_tags( $data[ 'field_id_with_meta_value' ] ) );
}
}
<?php
/**
* Example action and callback function to use with Caldera Forms Run Action
*
* Upadate specific option from Caldera Forms submission
*/
add_action('my_text_action', 'my_test_function');
function my_test_function( $data ){
update_option( 'test_form_option', $data );
}
@sakhavan
Copy link

sakhavan commented May 12, 2020

Hi,

Is this applicable in the free version of Caldera also? I need to call a Machine Learning model deployed in AWS when the user press submit , may you advise?

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