Forms

Retrieving form, field, action, and object models

<?php
// Returns an Form Model for Form ID 1
Ninja_Forms()->form( 1 )->get();
// Returns an array of Form Models for All Forms
Ninja_Forms()->form()->get_forms();
// Returns an array of Field Models for Form ID 1
Ninja_Forms()->form( 1 )->get_fields();
// Returns an array of Action Models for Form ID 1
Ninja_Forms()->form( 1 )->get_actions();
// Returns an array of Object Models for Form ID 1
Ninja_Forms()->form( 1 )->get_objects();

view raw
ninja-forms-form.php
hosted with ❤ by GitHub

Interacting with the Form Model

<?php
// Get the ID for a Model
$id = $model->get_id();
// Get a single setting for a Model by key
$setting = $model->get_setting( 'key' );
// Get all settings for a model
$settings = $model->get_settings();
// Get extra data stored with a submission.
$more_data = $model->get_extra_value( 'more_data' );
// Update a single setting for a model and save
$model->update_setting( 'key', 'value' )->save();
// Update an array of settings for a mdoel and save
$model->update_settings( $settings )->save();
// Delete a model
$model->delete();
// Save changes to a model
$model->save();

Putting it all together

<?php
/*
* Create a Form
*/
$form = Ninja_Forms()->form()->get();
$form->update_setting( 'title', 'Contact Me' );
$form->save();
/*
* Create a Form with an array of Settings
*/
$settings = array(
'title' => 'Contact Me'
);
$form = Ninja_Forms()->form()->get();
$form->update_settings( $settings )->save();
/*
* Update a Form
*/
$form = Ninja_Forms()->form( 1 )->get();
$form->update_setting( 'title', 'Contact Me' );
$form->save();
/*
* Update a Form with an array of Settings
*/
$settings = array(
'title' => 'Contact Me'
);
$form = Ninja_Forms()->form( 1 )->get();
$form->update_settings( $settings )->save();
/*
* Loop through Forms
*/
$forms = Ninja_Forms()->form()->get_forms();
foreach( $forms as $form ){
// Do Stuff Here
}