Last active
May 12, 2020 16:43
-
-
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/
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
<?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 **/ | |
} |
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
<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> |
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
<?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' ] ) ); | |
} | |
} |
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
<?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 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?