Dynamic Field Settings

A field’s settings can be set dynamically when the form is rendered on the page – this is when the field data is “localized” to the page for use by the form.

Related Filters

add_filter( ‘ninja_forms_localize_field’, ‘my_callback’ );

add_filter( ‘ninja_forms_localize_field_’ . $field_type, ‘my_callback’ );

Example

<?php
/**
* Change a field's settings when localized to the page.
*
* @param array $field [ id, settings => [ type, key, label, etc. ] ]
* @return array $field
*/
add_filter( 'ninja_forms_localize_field', function( $field ){
// Change the label setting of the field.
$field[ 'settings' ][ 'label' ] = 'New Field Label';
return $field;
});

Specific Field Type

<?php
/**
* Change a number field's settings when localized to the page.
*
* @param array $field [ id, settings => [ type, key, label, etc. ] ]
* @return array $field
*/
add_filter( 'ninja_forms_localize_field_number', function( $field ){
// Change the label setting of the field.
$field[ 'settings' ][ 'label' ] = 'New Number Field Label';
return $field;
});

Specific Field by Key

<?php
/**
* Change a field's settings when localized to the page.
*
* @param array $field [ id, settings => [ type, key, label, etc. ] ]
* @return array $field
*/
add_filter( 'ninja_forms_localize_field', function( $field ){
if( 'my_field' == $field[ 'settings' ][ 'key' ] ) {
// Change the label setting of the field.
$field[ 'settings' ][ 'label' ] = 'New Field Label';
}
return $field;
});

Other Examples