Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active July 8, 2019 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/7d46a94d02d979be279956ddd0d9ec1a to your computer and use it in GitHub Desktop.
Save Shelob9/7d46a94d02d979be279956ddd0d9ec1a to your computer and use it in GitHub Desktop.
<?php
/**
* Create a Caldera Forms entry programatically
*/
//Get the form entry is related to
//@TODO Change the form ID (cf123...)
$form = Caldera_Forms_Forms::get_form('cf1234456');
//Basic entry information
$entryDetials = new Caldera_Forms_Entry_Entry();
$entryDetials->form_id = $form['ID'];
$entryDetials->datestamp = current_time('mysql');
$entryDetials->status = 'pending';
//Create entry object
$entry = new Caldera_Forms_Entry(
$form,
false,
$entryDetials
);
//Get field to save value for
$field = Caldera_Forms_Field_Util::get_field('fld1233', $form);
//Create field value object
$fieldEntryValue = new Caldera_Forms_Entry_Field();
//Associate it with this field
$fieldEntryValue->field_id = $field['ID'];
$fieldEntryValue->slug = $field['slug'];
//Set the value to save.
$fieldEntryValue->value = 'THE VALUE OF THE ENTRY';
//Add field to entry
$entry->add_field($fieldEntryValue);
//Save entry in database.
$entryId = $entry->save();
//Make entry active
$entry->update_status( 'active' );
<?php
/**
* Edit a saved Caldera Forms entry programattically
*/
//Get the form entry is related to
//@TODO Change the form ID (cf123...)
$form = Caldera_Forms_Forms::get_form('cf1234456');
//@TODO set this to your saved entry ID
$entryId = 42;
//Get saved entry
$entry = new Caldera_Forms_Entry($form,$entryId );
//Get a field value
$field = $entry->get_field('fld12345');
$field->value = 'UPDATED VALUE';
//Update entry
$entry->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment