Skip to content

Instantly share code, notes, and snippets.

@orangerdev
Created August 5, 2021 04:08
Show Gist options
  • Save orangerdev/a513bd573e898800ca12ba157a906edf to your computer and use it in GitHub Desktop.
Save orangerdev/a513bd573e898800ca12ba157a906edf to your computer and use it in GitHub Desktop.
Save caldera form entry programmatically
$form_id = 'CF610b605dd7710';
$form = Caldera_Forms_Forms::get_form($form_id);
//Basic entry information
$entry_detail = new Caldera_Forms_Entry_Entry();
$entry_detail->form_id = $form['ID'];
$entry_detail->datestamp = current_time('mysql');
$entry_detail->status = 'pending';
$entry_detail->user_id = get_current_user_id();
//Create entry object
$entry = new Caldera_Forms_Entry($form, false, $entry_detail);
//Get form field setup
foreach( $form['fields'] as $field_id => $field_detail ) :
$field = Caldera_Forms_Field_Util::get_field($field_id, $form);
$field_entry_value = new Caldera_Forms_Entry_Field();
$field_entry_value->field_id = $field['ID'];
$field_entry_value->slug = $field['slug'];
$field_entry_value->value = rand(0, 1000); // This is a random value, later need to setup manually
$entry->add_field($field_entry_value);
endforeach;
$entry_id = $entry->save();
$entry->update_status( 'active' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment