Add Custom Preset Options for Caldera Forms Select Fields

Caldera Forms Banner

New Caldera Forms Preset optionsCaldera Forms 1.4.0 added support for adding presets to select fields such as dropdown fields. Caldera Forms ships with several presets. But you can add your own using the caldera_forms_field_option_presets filter.

If you have a preset list you’d like to see included in the next version of Caldera Forms, open a pull request to add one, or open an issue with just the list.

To add a preset you need two things. The first is a text file that includes the options. This file should have one preset per line. A “|” character is used to separate value from label.

For example:

josh|Josh Pollock
roy|Roy Sivan
shawn|Shawn M. Hooper

Using separate values and labels is not required, but is recommended. For example, this list would keep label and value the same:

Josh
Roy
Shawn

Once you have this list, you can then use it in a callback function hooked to the ‘caldera_forms_field_option_presets’ filter. Make sure that the path is correct for your text file:

add_filter( 'caldera_forms_field_option_presets', function( $presets ){

	$presets[ 'names-list' ] = array(
		'name' => 'Names of People',
		'data' => file_get_contents( 'path/to/file.txt' ),
	);

	return $presets;

});

Better Emails, Better Form Builder: Better Caldera Forms

Where Does This Code Go?

When using WordPress hooks to customize Caldera Forms or other plugins you should not modify the plugin files, or you will lose your changes when you update the plugin. Instead you should create a small plugin to hold the custom code. It's easy, learn how here.

Technically you can add the custom code to your theme's functions.php, but then you will not be able to change your theme and keep these customizations.

Learn More