From 2983bcb56b2369fc0e53c574485d2ea55acf3753 Mon Sep 17 00:00:00 2001
From: Markus Birth
Date: Tue, 24 May 2016 02:39:23 +0200
Subject: [PATCH] Added templates for different INPUT fields. prep_form needs
cleanup!
---
prep_form.php | 25 +++++++++++++----
templates/hotel_html.mustache | 23 ++++++----------
templates/partials/mdl_input.mustache | 27 +++++++++++++++++++
templates/partials/mdl_input_country.mustache | 7 +++++
.../partials/mdl_input_datetime.mustache | 7 +++++
templates/partials/mdl_input_decimal.mustache | 7 +++++
templates/partials/mdl_input_email.mustache | 7 +++++
templates/partials/mdl_input_number.mustache | 7 +++++
templates/partials/mdl_input_status.mustache | 8 ++++++
templates/partials/mdl_input_tel.mustache | 7 +++++
templates/partials/mdl_input_text.mustache | 7 +++++
templates/partials/mdl_input_url.mustache | 7 +++++
12 files changed, 119 insertions(+), 20 deletions(-)
create mode 100644 templates/partials/mdl_input.mustache
create mode 100644 templates/partials/mdl_input_country.mustache
create mode 100644 templates/partials/mdl_input_datetime.mustache
create mode 100644 templates/partials/mdl_input_decimal.mustache
create mode 100644 templates/partials/mdl_input_email.mustache
create mode 100644 templates/partials/mdl_input_number.mustache
create mode 100644 templates/partials/mdl_input_status.mustache
create mode 100644 templates/partials/mdl_input_tel.mustache
create mode 100644 templates/partials/mdl_input_text.mustache
create mode 100644 templates/partials/mdl_input_url.mustache
diff --git a/prep_form.php b/prep_form.php
index 111720d..856bc9c 100644
--- a/prep_form.php
+++ b/prep_form.php
@@ -8,10 +8,14 @@ $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();
+ $by_group[$group] = array(
+ 'group_name' => $group,
+ 'fields' => array(),
+ );
}
foreach ($field_data['fields'] as $key=>$meta) {
+ $meta['field_id'] = $key;
$group_name = $field_data['groups'][$meta['group']];
$meta['group_name'] = $group_name;
if (isset($_SESSION[$skey][$key])) {
@@ -19,16 +23,27 @@ foreach ($field_data['fields'] as $key=>$meta) {
} elseif (isset($meta['default'])) {
switch ($meta['default']) {
case 'USER_NAME':
- $meta['value'] = 'User Name';
+ $meta['value'] = $data['user']['name_first'] . ' ' . $data['user']['name_last'];
break;
case 'USER_EMAIL':
- $meta['value'] = 'user@email.com';
+ $meta['value'] = $data['user']['email'];
break;
default:
$meta['value'] = $meta['default'];
break;
}
}
- $by_group[$group_name][$key] = $meta;
+ $meta['fieldtype_' . $meta['type']] = true;
+ if ($meta['type'] == 'datetime') {
+ $meta['min'] = date('Y-m-d');
+ }
+ $by_group[$group_name]['fields'][$key] = $meta;
}
-print_r($by_group);
+
+foreach ($by_group as $group=>$group_data) {
+ $by_group[$group]['fields'] = array_values($group_data['fields']);
+}
+
+#print_r($by_group);
+$by_group = array_values($by_group);
+$data['form_data'] = $by_group;
diff --git a/templates/hotel_html.mustache b/templates/hotel_html.mustache
index 6eb2c50..6292349 100644
--- a/templates/hotel_html.mustache
+++ b/templates/hotel_html.mustache
@@ -10,22 +10,15 @@
+{{#form_data}}
+{{group_name}}
-
-
-
-
-
- Input is empty or not a date!
-
-
+ {{#fields}}
+ {{>mdl_input}}
+ {{/fields}}
+
+
+{{/form_data}}