Last active
February 20, 2018 11:34
-
-
Save Shelob9/3adb49541bc46ef32f147f9f27a87908 to your computer and use it in GitHub Desktop.
Example code for action that runs after Caldera Forms submission is processed, but before it is saved. For more information see: https://calderaforms.com/doc/caldera_forms_submit_post_process/
This file contains hidden or 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 | |
add_action( 'caldera_forms_submit_post_process', function( $form, $referrer, $process_id, $entry_id ){ | |
//make sure to set your field ID here. | |
$field_id = 'fld_123456'; | |
//Get value of a field | |
$field_value = Caldera_Forms::get_field_data( $field_id, $entry_id, $form ); | |
//check value | |
if( in_array( $field_value, array( 'Roy', 'Shawn' )) ){ | |
//change value | |
Caldera_Forms::set_field_data( $field_id, 'Mike', $form, $entry_id ); | |
} | |
}, 10, 4 ); |
This file contains hidden or 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 | |
add_action( 'caldera_forms_submit_post_process', function( $form, $referrer, $process_id, $entry_id ){ | |
//Save field data from a SESSION var if it is set | |
if( isset( $_SESSION, $_SESSION[ 'foo' ] ) ){ | |
//make sure to update the field ID | |
Caldera_Forms::set_field_data( 'fld1234567', $_SESSION[ 'foo' ], $form, $entry_id ); | |
} | |
}, 10, 4 ); |
This file contains hidden or 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 | |
add_action( 'caldera_forms_submit_post_process', function( $form, $referrer, $process_id, $entry_id ){ | |
//IMPORTANT -- Change the form ID to match your form | |
if( 'CF57c872a1c80af' == $form[ 'ID' ] ){ | |
//IMPORTANT -- Change the field ID to match your post select field | |
$field_id = 'fld_5702696'; | |
//get the Post ID from current field value | |
$post_id = Caldera_Forms::get_field_data( $field_id, $form, $entry_id ); | |
if( is_numeric( $post_id ) ){ | |
//get title, by ID and set it as field value | |
$title = get_the_title( $post_id ); | |
Caldera_Forms::set_field_data( $field_id, $title, $form, $entry_id ); | |
} | |
} | |
}, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Shelob9 First example l7 sets the arguments in the wrong order. It should be $field_value = Caldera_Forms::get_field_data( $field_id, $form, $entry_id );