Fields

Retrieving the Field Model

<?php
// Returns a Field Model for Field ID 1
$model = Ninja_Forms()->form()->field( 1 )->get();
// Returns a Field Model for Field ID 1
$model = Ninja_Forms()->form()->get_field( 1 );
// Returns an array of Field Models for Form ID 1
$models = Ninja_Forms()->form( 1 )->get_fields();

Interacting with the Field 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 Field
*/
$field = Ninja_Forms()->form( 1 )->field()->get();
$field->update_settings( 'type', 'textbox' )->save();
/*
* Create a Field with an array of Settings
*/
$settings = array(
'type' => 'textbox',
'label' => 'name',
'label_post' => 'inside',
'required' => 1
);
$field = Ninja_Forms()->form( 1 )->field()->get();
$field->update_settings( $settigns )->save();
/*
* Update a Field
*/
$field = Ninja_Forms()->form()->field( 1 )->get();
$field->update_settings( 'type', 'textbox' )->save();
/*
* Update a Field with an array of Settings
*/
$settings = array(
'type' => 'textbox',
'label' => 'name',
'label_post' => 'inside',
'required' => 1
);
$field = Ninja_Forms()->form()->field( 1 )->get();
$field->update_settings( $settigns )->save();
/*
* Loop through Fields
*/
$fields = Ninja_Forms()->form( 1 )->get_fields();
foreach( $fields as $field ){
// Do Stuff Here
}