Last active
July 8, 2019 12:53
-
-
Save Shelob9/7d46a94d02d979be279956ddd0d9ec1a to your computer and use it in GitHub Desktop.
Create and edit Caldera Forms entries using PHP code. See: https://calderaforms.com/doc/caldera_forms_entry-class/ & https://calderaforms.com/doc/edit-caldera-forms-entries-php/
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 | |
/** | |
* 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' ); | |
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 | |
/** | |
* 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