Last active
October 20, 2019 13:18
-
-
Save DavidCramer/c65b3eaa80db7256689f to your computer and use it in GitHub Desktop.
Getting submission data in a from processor in Caldera Forms
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 | |
/** | |
* Plugin Name: CF Get Submission Data | |
* Plugin URI: | |
* Description: Example in getting submission data in a form processor | |
* Version: 1.0.0 | |
* Author: David Cramer | |
* Author URI: | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
*/ | |
// function to register the form processor | |
function get_submit_example_processor_register( $processors ) { | |
// Add our processor to the $processors array using our processor_slug as the key. | |
// It is possible to replace an existing processor by redefining it and hooking in with a lower priority i.e 100 | |
$processors['my_processor_slug'] = array( | |
"name" => "Dump Submission Data", // Required : Processor name | |
"description" => "Example of getting the submission data", // Required : Processor description | |
"processor" => 'get_submit_example_processor_function', // Optional : Processor function to do stuff | |
); | |
return $processors; | |
} | |
// add filter to use the processor register | |
add_filter( 'caldera_forms_get_form_processors', 'get_submit_example_processor_register' ); | |
// processor function | |
function get_submit_example_processor_function($config, $form){ | |
// build a data array of submitted data | |
$data = array(); | |
// Raw data is an array with field_id as the key | |
$raw_data = Caldera_Forms::get_submission_data( $form ); | |
// create a new array using the slug as the key | |
foreach( $raw_data as $field_id => $field_value ){ | |
// dont add buttons or html fields to data array as they are not capture values | |
if( in_array( $form[ 'fields' ][ $field_id ][ 'type' ], array( 'button', 'html' ) ) ) | |
continue; | |
// get the field slug for the key instead | |
$data[ $form[ 'fields' ][ $field_id ][ 'slug' ] ] = $field_value; | |
} | |
// $data should contain slug:value | |
// Heres an output to show on screen. | |
echo '<pre>'; | |
echo "Raw Data\r\n"; | |
print_r( $raw_data ); | |
echo "\r\nClean Data\r\n"; | |
print_r( $data ); | |
echo '</pre>'; | |
die; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Desertsnowman, I am needing to capture caldera form submitted data and insert it into a table (not very successfully as I am not a programmer (wannabe;). I have a PHP routine I have used for another form product I think will work to take the caldera array information and put it in the table.
My challenge (at least one of them;) is I cannot see what the array of data looks like to convert it. I found your code and hoped it might work. I inserted it into a Post Snippets with get_submit_example_processor_register as the shortcode name. I also added get_submit_example_processor_register as the action as a processor on a form with a hidden userid, text and number fields.
When I add the caldera form to a page and view, enter data and submit the form submits but nothing else. I was expecting to see the array on the page. I could be completely miss understanding what you have done here.
If you have any advice I would greatly appreciate it. I seem to be swimming up current on what I had hoped was a relatively trivial task.
Thanks!