caldera_forms_render_field

Caldera Forms -- Responsive, drag and drop form builder.

This filter can be used for changing a field’s configuration in anyway. A very useful thing to do with it is to modify the options of a select field:

<?php
add_filter( 'caldera_forms_render_get_field', function( $field )  {
    if ( 'stores_in_pa' == $field[ 'slug' ]  ) {
        $stores = get_posts( array( 'post_type' => 'stores', 'meta_key' => 'state', 'meta_value' => 'PA' ) );
        if ( ! empty( $stores ) ) {
            foreach( $stores as $store ) {
                $field[ 'config' ][ 'option' ][ $store->ID ] = array(
                    'value' => $store->ID,
                    'label' => $store->post_title
                );
            }
        }
    }

    return $field;

});

You can also use this filter to translate a field’s description, name, placeholder, or other settings. For example:

add_filter( 'caldera_forms_render_get_field', function( $field ) {
    if ( 'hats' == $field[ 'id' ] ) {
        $language = get_locale();
        if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
            $language = ICL_LANGUAGE_CODE;
        }

        if( 'es_ES' == $language ) {
            $field[ 'caption' ] = 'Odio tipo';
        }
    }

    return $field;
    
});

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