How can I get data from Ninja Forms to appear in frontend?

4.6k Views Asked by At

I just know a little bit about Javascript, I'm not a programmer yet. I created a Ninja Forms to be used in my Wordpress site. When a user fills out the 4 fields of the form and press Submit, I need those data to appear always in the frontend ( in their 4 specific places I've created in html), and the last one submitted overwrite to the previous one.

Ninja is saving the data in wp_postmeta like this:

    **meta_key**   **meta_value**
    _field_12     (the first of the values I want appear in frontend)
    _field_13     (the second one)
    _field_14     (the third one)
    _field_15     (the fourth one)
    _form_id      1 (always the same value)
    _seq_num      3 (increase 1 every time Submit is pressed)

How can I do it? I know is out of my range without PHP knowledge but, can someone give me some trick? Is there a plugin to get it?

Help, please

1

There are 1 best solutions below

2
On

You have several options:

  1. Create a custom Ninja Forms Action. This obviously will require significant amount of programming skills, understanding how Ninja Forms works, etc. Advantage, you could store your data in preferred location and format (e.g. in wp_options table).

  2. Hackfix the problem. You can probably do something like this in your template:

.

$form_id = 3;
$submissions = Ninja_Forms()->form( $form_id )->get_subs();
if ( is_array( $submissions ) && count( $submissions ) > 0 ) {

    // Get first element of array; latest submission
    $latest_submission = reset( $submissions );

    // Returns array with all submission values
    $all_fields = $latest_submission->get_field_values();
    print_r( $all_fields );

    // To get/display single value
    $single_field = $latest_submission->get_field_value( 'firstname_1531139833971' );
    echo $single_field;
}

If you not sure about form ID, check the id listed in shortcode (Ninja Forms -> Dashboard, then shortcode column). E.g. [ninja_form id=3] id=3 is your form_id.

Easiest way to obtain key for method get_field_value is to print_r all submission values and check which one is which one, otherwise, click to edit form, select field to edit, expand administration section and you should see the key for that field.

enter image description here

Option #1 should be preferred method to address this issues, if you intend to proceed with option #2 make sure to check function Ninja_Forms() exists first, otherwise you will get fatal errors if Ninja Forms is disabled/not loaded/etc.