This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
Replace [type] in the hook with the name of the field type. This adds settings into the field-specific section in the field settings.
Usage
add_action( 'frm_radio_primary_field_options', 'add_custom_field_settings' ); function add_custom_field_settings( $args )
Parameters
- $args (array)
- 'field' (array)
- 'display' (array) - A list of field options that should be shown for the current field.
- 'values' (array) - Details about the form.
Examples
Add custom setting to text field options
This code example doesn't handle saving the value. To properly store this setting, register it in the default options array using the frm_default_field_options filter or create your own saving handler
add_action( 'frm_text_primary_field_options', 'custom_field_settings' );
function custom_field_settings( $args ) {
$field = $args['field'];
$custom_setting = isset( $field['custom_setting'] ) ? $field['custom_setting'] : '';
?>
<p>
<label for="custom-setting-<?php echo intval( $field['id'] ); ?>">
<?php esc_html_e( 'Custom setting', 'text-domain' ); ?>
</label>
<input type="text" id="custom-setting-<?php echo intval( $field['id'] ); ?>" name="field_options[custom_setting_<?php echo intval( $field['id'] ); ?>]" value="<?php echo esc_attr( $custom_setting ); ?>" />
</p>
<?php
}
add_filter( 'frm_default_field_options', 'add_custom_field_option', 10, 2 );
function add_custom_field_option( $options, $args ) {
if ( 'text' === $args['type'] ) {
$options['custom_setting'] = '';
}
return $options;
}