• Resolved M

    (@imlongcat)


    So i modify a form with the ninja_forms_pre_process hook and it works great. I calculate something out of the user-input values and want to show the result on screen.

    For a text area element i can use
    $ninja_forms_processing->update_field_value(10, $htmlstr );
    and it puts the text into my form element, but this does not work with the Layout Element “Text”. I suppose it’s because this element does not have a field value, but how can i change this on the fly?

    The documentation does not really help much or i simply couldn’t find the relevant setting for the Text element.

    http://ww.wp.xz.cn/extend/plugins/ninja-forms/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Kevin Stover

    (@kstover)

    You are correct in assuming that it’s not sent with the $ninja_forms_field->get_field_value() or update_field_value(). You can change it fairly easily using the ‘ninja_forms_field’ WordPress filter.

    Here’s the doc on the filter itself: http://wpninjas.com/ninja-forms/docs/ninja_forms_field/

    You’ll want to return $data with a new value set for: $data[‘default_value’]. Whatever you have that variable equal to will be displayed in the Text Layout Element.

    Thread Starter M

    (@imlongcat)

    How can i manually fire the filter function? it works in principle but it should be executed when i have calculated something via the pre_process hook.

    if that is not related enough to Ninja Forms please close the thread. you can set it to resolved nevertheless since the $data[‘default_value’] works. thanks for the quick help!

    Plugin Author Kevin Stover

    (@kstover)

    The filter is a WordPress filter. You just use the add_filter() function and your function will fire whenever the filter is triggered.

    Plugin Author Kevin Stover

    (@kstover)

    So, you do something like this inside your pre_process function:

    function my_pre_process_function(){
    add_filter( ‘ninja_forms_field’, ‘my_filter_function’, 10, 2 );
    }

    Then you’d add a function to actually do the filtering.

    function my_filter_function( $data, $field_id ){
    if( $field_id = 3 ){
    $data[‘default_value’] = “My New Text Value”;
    }
    $return $data;
    }

    Thread Starter M

    (@imlongcat)

    Works like a charm. Sorry to bother you with this stupid questions.

    Thanks again! If you have Paypal i’d donate $10.

    Plugin Author James Laws

    (@jameslaws)

    No donation necessary. We make our revenue from the sale of our extensions for Ninja Forms and are happy to assist others in getting the most out of it. 🙂

    We really hope to make the Ninja Forms Core a more community driven project.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Changing layout element "Text" content via hooks/actions’ is closed to new replies.