• pparkadmin

    (@pparkadmin)


    So this may be a dumb question, I can see how to setup a function to change a field dynamically in a form, but it only seems to work on the first field I set, what if I need to change multiple fields in a single form?

    add_filter( 'caldera_forms_render_get_field', function( $field )  {
        if( 'fld_8915153' == $field[ 'ID' ] ){
                        $field[ 'config' ][ 'default' ] = 125;
        }
        return $field;
    }, 10, 2 );

    This code will only change one field but I need to fill at least 10 fields with dynamic data.

Viewing 1 replies (of 1 total)
  • Thread Starter pparkadmin

    (@pparkadmin)

    Ok so I have added unique function names now for each of these 2 functions, is there a better way than adding a function for each field I want to change?

    add_filter( 'caldera_forms_render_get_field', 'wireless_service_cost_1', 10, 2 );
        function wireless_service_cost_1( $field ) {
            if( 'fld_8915153' == $field[ 'ID' ] ){
                    $field[ 'config' ][ 'default' ] = 125;
            }
            return $field;
        }
    
    add_filter( 'caldera_forms_render_get_field', 'wireless_service_cost_2', 10, 2 );
    function wireless_service_cost_2( $field ) {
        if( 'fld_8185489' == $field[ 'ID' ] ){
                $field[ 'config' ][ 'default' ] = 25;
        }
        return $field;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Setting Field Default Values Dynamically (multiple)’ is closed to new replies.