Refined JSON. Added form preparation.

This commit is contained in:
2016-05-23 17:19:41 +02:00
parent c582af6e79
commit 891c9db21d
3 changed files with 240 additions and 192 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
// FOR TESTING:
$action = 'hotel';
$skey = 'form_' . $action;
$field_data_json = file_get_contents('definitions/' . $action . '.json');
$field_data = json_decode($field_data_json, true);
foreach ($field_data['groups'] as $id=>$group) {
$by_group[$group] = array();
}
foreach ($field_data['fields'] as $key=>$meta) {
$group_name = $field_data['groups'][$meta['group']];
$meta['group_name'] = $group_name;
if (isset($_SESSION[$skey][$key])) {
$meta['value'] = $_SESSION[$skey][$key];
} elseif (isset($meta['default'])) {
switch ($meta['default']) {
case 'USER_NAME':
$meta['value'] = 'User Name';
break;
case 'USER_EMAIL':
$meta['value'] = 'user@email.com';
break;
default:
$meta['value'] = $meta['default'];
break;
}
}
$by_group[$group_name][$key] = $meta;
}
print_r($by_group);