Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Pre Populate a Ninja Form hidden field from an Advanced Custom Field?

I have Ninja Forms and ACF for WordPress installed. I have a hidden field in Ninja Forms and I need to repopulate this with the value from an ACF field.

I tried simple jQuery but it doesn't work:

$('input[name=nf-field-19]').val('<?php the_field('rsvp_email'); ?>');

As you can tell.. I'm no PHP or jQuery guy.. trying to fiddle around and find a solution.

Thanks!

like image 231
conradical Avatar asked Feb 01 '18 04:02

conradical


People also ask

How do you create a hidden field in ninja form?

You'll want to make sure you add a hidden field to your form first and leave the Default Value empty. Once your users submit your form, you can navigate to Ninja Forms > Submissions and select the submission where you would like to add some extra notes. Click Edit. This will open a pop-up with user-submitted values.

How do you add conditional logic in ninja form?

Make sure the Value of your form fields is filled out. Then you'll want to head to the Advanced tab and select Conditional Logic. Here you can add conditions for your form fields. That's it! You've just learned how to create dynamic fields and show the fields based on the user's input on your form.

How do you make a multi step form in ninja?

Creating a Multi Step FormStart by adding fields to the first part of your form. Once you add a field, you should see a grey circle/+ sign show up in the bottom right of the form builder. Once the part is added, you can then edit its settings by clicking on the tab that appears at the bottom of the screen.


1 Answers

Do you need this to work from JS for some reason? I am using the ninja_forms_render_default_value filter hook to prepopulate hidden form fields:

/**
 * Populate hidden input with ACF values
 */
function nf_hidden_field_values( $value, $field_type, $field_settings ) {
    global $post;
    $value = ''
    if ( $field_settings['key'] == 'hidden_field_1' ) {
        $value =  get_field('acf_field_1', $post->ID);
    }

    if ( $field_settings['key'] == 'hidden_field_2' ) {
        $value = get_field('acf_field_2', $post->ID);
    }

    return $value;
}
add_filter( 'ninja_forms_render_default_value', 'nf_hidden_field_values', 10, 3 );
like image 80
cr0ybot Avatar answered Sep 21 '22 14:09

cr0ybot