Skip to content

Instantly share code, notes, and snippets.

@gandalfar gandalfar/script.php
Created Jan 29, 2014

Embed
What would you like to do?
Returns results of Wordpress Ninja Forms as AJAX friendly JSON ouput (for angular.js)
<?php
$subs = ninja_forms_get_all_subs( 1 );
$fields = ninja_forms_get_fields_by_form_id( 1 );
$json_data = [];
foreach ($subs as $sub_id => $sub) {
$submission_data = array();
$data = unserialize($sub['data']);
$user_values = array();
foreach ($data as $key => $value) {
$user_values[$value['field_id']] = $value['user_value'];
}
foreach ( $fields as $field_id => $field ) {
$user_value = $user_values[$field['id']];
if ($user_value == '') {
continue;
}
$submission_data[] = array(
"label" => $field['data']['label'],
"value" => $user_value,
"type" => $field['type']
);
}
$json_data[] = array(
"id" => $sub['id'],
"items" => array_values($submission_data)
);
echo json_encode(array_values($json_data), JSON_PRETTY_PRINT);
}
?>
@feyazbeck

This comment has been minimized.

Copy link

commented Apr 5, 2016

Hello,

Can you please have the kindness and support a newbie to WP? Where would you add this code in WP?

Thank you,
FEY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.