Skip to content

Instantly share code, notes, and snippets.

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/3adb49541bc46ef32f147f9f27a87908 to your computer and use it in GitHub Desktop.
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/
<?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 );
<?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 );
<?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 );
@New0
Copy link

New0 commented Feb 20, 2018

@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 );

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