From a0f29185664b8e4b007a9ff83c8c9e6b6f2cd678 Mon Sep 17 00:00:00 2001 From: Carsten Rose <carsten.rose@math.uzh.ch> Date: Sat, 16 Apr 2016 19:33:27 +0200 Subject: [PATCH] FillStoreForm.php, Constants.php: form element status 'required' not respected - fixed. formEditor.sql: Form and FormElement field 'name' is now 'required' --- extension/qfq/qfq/Constants.php | 9 +++++- extension/qfq/qfq/store/FillStoreForm.php | 38 ++++++++++++++++------- extension/qfq/sql/formEditor.sql | 4 +-- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php index 339fa0e67..9db134590 100644 --- a/extension/qfq/qfq/Constants.php +++ b/extension/qfq/qfq/Constants.php @@ -41,7 +41,7 @@ const RETURN_ARRAY = 'return_array'; const SQL_FORM_ELEMENT_SPECIFIC_CONTAINER = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.feIdContainer = ? AND fe.enabled='yes' ORDER BY fe.ord, fe.id"; const SQL_FORM_ELEMENT_ALL_CONTAINER = "SELECT *, ? AS 'nestedInFieldSet' FROM FormElement AS fe WHERE fe.formId = ? AND fe.deleted = 'no' AND FIND_IN_SET(fe.class, ? ) AND fe.enabled='yes' ORDER BY fe.ord, fe.id"; -const SQL_FORM_ELEMENT_SIMPLE_ALL_CONTAINER = "SELECT fe.id, fe.name, fe.type, fe.checkType, fe.checkPattern FROM FormElement AS fe, Form AS f WHERE f.name = ? AND f.id = fe.formId AND fe.deleted = 'no' AND fe.class = 'native' AND fe.enabled='yes' ORDER BY fe.ord, fe.id"; +const SQL_FORM_ELEMENT_SIMPLE_ALL_CONTAINER = "SELECT fe.id, fe.name, fe.label, fe.type, fe.checkType, fe.checkPattern, fe.mode FROM FormElement AS fe, Form AS f WHERE f.name = ? AND f.id = fe.formId AND fe.deleted = 'no' AND fe.class = 'native' AND fe.enabled='yes' ORDER BY fe.ord, fe.id"; // SANITIZE Classifier const SANITIZE_ALLOW_ALNUMX = "alnumx"; @@ -332,6 +332,13 @@ const GLYPH_ICON_SHOW = 'glyphicon glyphicon-search'; const GLYPH_ICON_TOOL = 'glyphicon-wrench'; const GLYPH_ICON_CHECK = 'glyphicon glyphicon-ok'; +// FORM_ELEMENT_STATI +const FE_MODE_SHOW = 'show'; +const FE_MODE_READONLY = 'readonly'; +const FE_MODE_REQUIRED = 'required'; +const FE_MODE_LOCK = 'lock'; +const FE_MODE_DISABLED = 'disabled'; + // SUPPORT const PARAM_T3_ALL = 't3 all'; const PARAM_T3_NO_ID = "t3 no id"; diff --git a/extension/qfq/qfq/store/FillStoreForm.php b/extension/qfq/qfq/store/FillStoreForm.php index 9e69e47e6..8d9d99572 100644 --- a/extension/qfq/qfq/store/FillStoreForm.php +++ b/extension/qfq/qfq/store/FillStoreForm.php @@ -12,6 +12,7 @@ require_once(__DIR__ . '/Store.php'); require_once(__DIR__ . '/../Database.php'); require_once(__DIR__ . '/../Constants.php'); require_once(__DIR__ . '/../helper/HelperFormElement.php'); +require_once(__DIR__ . '/../exceptions/UserFormException.php'); class FillStoreForm { @@ -99,22 +100,37 @@ class FillStoreForm { continue; } - if (isset($clientValues[$clientFieldName])) { + switch ($formElement['mode']) { + case FE_MODE_SHOW: + case FE_MODE_REQUIRED: + if (isset($clientValues[$clientFieldName]) && ($clientValues[$clientFieldName] != '')) { - // SELECT with multiple values, or Multi CHECKBOX are delivered as array: implode them - if (is_array($clientValues[$clientFieldName])) { - // E.g. Checkboxes needs a 'HIDDEN' HTML input to detect 'unset' of values. These 'HIDDEN' element - // needs to be removed, if there is at least one checkbox is checked (=submitted) - if (count($clientValues[$clientFieldName]) > 1) - array_shift($clientValues[$clientFieldName]); + // SELECT with multiple values, or Multi CHECKBOX are delivered as array: implode them + if (is_array($clientValues[$clientFieldName])) { + // E.g. Checkboxes needs a 'HIDDEN' HTML input to detect 'unset' of values. These 'HIDDEN' element + // needs to be removed, if there is at least one checkbox is checked (=submitted) + if (count($clientValues[$clientFieldName]) > 1) + array_shift($clientValues[$clientFieldName]); - $clientValues[$clientFieldName] = implode(',', $clientValues[$clientFieldName]); - } + $clientValues[$clientFieldName] = implode(',', $clientValues[$clientFieldName]); + } // $newValues[$formElement['name']] = $this->validateValue($formElement, $clientValues[$clientFieldName]); - $newValues[$formElement['name']] = Sanitize::sanitize($clientValues[$clientFieldName], $formElement['checkType'], $formElement['checkPattern'], SANATIZE_EXCEPTION); + $newValues[$formElement['name']] = Sanitize::sanitize($clientValues[$clientFieldName], $formElement['checkType'], $formElement['checkPattern'], SANATIZE_EXCEPTION); + } else { + if ($formElement['mode'] === FE_MODE_REQUIRED) { + throw new UserFormException("Missing required value for '" . $formElement['name'] . ' / ' . $formElement['label'] . "'", ERROR_UNKNOWN_MODE); + } + } + break; + + case FE_MODE_READONLY: + case FE_MODE_LOCK: + case FE_MODE_DISABLED: + continue; + default: + throw new CodeException("Unknown mode: " . $formElement['mode'], ERROR_UNKNOWN_MODE); } - } $this->store->setVarArray($newValues, STORE_FORM, true); diff --git a/extension/qfq/sql/formEditor.sql b/extension/qfq/sql/formEditor.sql index 37bffb79f..6136b0e97 100644 --- a/extension/qfq/sql/formEditor.sql +++ b/extension/qfq/sql/formEditor.sql @@ -132,7 +132,7 @@ VALUES (1, 'formelement', 'Formelement', 'show', 'pill', 'all', 'container', 50, 0, 0, '', '', '', '', '', '', 0, ''), (1, 'id', 'id', 'readonly', 'text', 'all', 'native', 100, 10, 11, '', '', '', '', '', '', 1, ''), - (1, 'name', 'Name', 'show', 'text', 'all', 'native', 120, 40, 255, '', '', '', '', '', 'autofocus', 1, ''), + (1, 'name', 'Name', 'required', 'text', 'all', 'native', 120, 40, 255, '', '', '', '', '', 'autofocus', 1, ''), (1, 'title', 'Title', 'show', 'text', 'all', 'native', 130, 40, 255, '', '', '', '', '', '', 1, ''), (1, 'noteInternal', 'Note', 'show', 'text', 'all', 'native', 140, '40,3', 0, '', '', '', '', '', '', 1, ''), (1, 'tableName', 'Table', 'required', 'select', 'all', 'native', 150, 0, 0, '', '', '', '{{!SHOW tables}}', '', 'emptyItemAtStart', 1, ''), @@ -195,7 +195,7 @@ VALUES '', 'emptyItemAtStart', 100, '', 'no'), (2, 'enabled', 'Enabled', 'show', 'checkbox', 'all', 'native', 130, 0, 0, '', '', '', '', '', '', 100, '', 'no'), (2, 'dynamicUpdate', 'Dynamic Update', 'show', 'checkbox', 'all', 'native', 135, 0, 0, 'This element will be updated on change and trigger other.', '', '', '', '', '', 100, '', 'no'), - (2, 'name', 'Name', 'show', 'text', 'all', 'native', 140, 40, 255, '', '', '', '', '', '', 100, '', 'no'), + (2, 'name', 'Name', 'required', 'text', 'all', 'native', 140, 40, 255, '', '', '', '', '', '', 100, '', 'no'), (2, 'label', 'Label', 'show', 'text', 'all', 'native', 150, 40, 255, '', '', '', '', '', '', 100, '', 'no'), (2, 'mode', 'Mode', 'show', 'select', 'all', 'native', 160, 0, 255, '', '', '', '', '', '', 100, '', 'no'), (2, 'class', 'Class', 'show', 'select', 'all', 'native', 170, 0, 255, '', '', '{{class:FSRD0:alnumx}}', '', '', '', 100, '', 'yes'), -- GitLab