Created
January 29, 2014 18:08
-
-
Save jurecuhalev/8693543 to your computer and use it in GitHub Desktop.
Returns results of Wordpress Ninja Forms as AJAX friendly JSON ouput (for angular.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Can you please have the kindness and support a newbie to WP? Where would you add this code in WP?
Thank you,
FEY