wordpressadvanced-custom-fieldsninja-forms

Pass the value of the ACF field to the hidden Ninja forms field


There is an ACF field group. This group has a repeater field. In the repeater, a text field whose value must be passed to the hidden field of the Ninja Forms form.

Key a hidden field Ninja Forms «cost_1565849718636». ACF group «group_5d489118f0d20», repeater field «field_5d48911907c30», text sub field «field_5d48933edcdd7».

I will be grateful for the help, just learning)

I tried it, but it doesn't work. Perhaps because the ACF field is in the repeater?

    function nf_hidden_field_values( $value, $field_type, $field_settings ) {
        global $post;

        if ( $field_settings['key'] == 'cost_1565849718636' ) {
            return get_field('field_5d48933edcdd7', $post->ID);
        }

        return $value;
    }
    add_filter( 'ninja_forms_render_default_value', 'nf_hidden_field_values', 10, 3 );

Solution

  • Itself asked - itself answered). Can someone come in handy)

        add_filter( 'ninja_forms_render_default_value', 'wm_the_value' , 10 , 3);
        function wm_the_value( $default_value, $field_type, $field_settings ) {
            if ( $field_settings['key'] == 'cost1') {
                if ( have_rows( 'field_5d48911905103' ) ) {
                    while ( have_rows( 'field_5d48911905103' ) ) { the_row();
                        if( have_rows('field_5d48911907c30') ){
                            while( have_rows('field_5d48911907c30') ){ the_row();
                                $default_value = get_sub_field('field_5d48933edcdd7');
                            }
                        }
                    }
                }
            }
            return $default_value;
        }