diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php index 8925bf2b032565ffda111393cd7cec3a95f46a1f..22874b2949b57ef1f6f7e2f8a65fc6d1ebcac78b 100644 --- a/extension/qfq/qfq/AbstractBuildForm.php +++ b/extension/qfq/qfq/AbstractBuildForm.php @@ -840,7 +840,7 @@ abstract class AbstractBuildForm { } if ($formElement['checkBoxMode'] === 'multi') { - $htmlFormElementId .= '[]'; +// $htmlFormElementId .= '[]'; } else { // Fill meaningfull defaults to parameter: checked|unchecked (CHECKBOX_VALUE_CHECKED|CHECKBOX_VALUE_UNCHECKED) $this->prepareCheckboxCheckedUncheckedValue($itemKey, $formElement); @@ -1080,10 +1080,10 @@ abstract class AbstractBuildForm { // Defines which of the checkboxes will be checked. $values = explode(',', $value); - $attributeBase .= Support::doAttribute('name', $htmlFormElementId); +// $attributeBase .= Support::doAttribute('name', $htmlFormElementId); $attributeBase .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : ''); - $html = $this->buildNativeHidden($htmlFormElementId, ''); + $html = $this->buildNativeHidden(HelperFormElement::prependFormElementIdCheckBoxMulti($htmlFormElementId, 'h'), ''); $orientation = ($formElement['maxLength'] > 1) ? ALIGN_HORIZONTAL : ALIGN_VERTICAL; $checkboxClass = ($orientation === ALIGN_HORIZONTAL) ? 'checkbox-inline' : 'checkbox'; @@ -1093,6 +1093,7 @@ abstract class AbstractBuildForm { for ($ii = 0, $jj = 1; $ii < count($itemKey); $ii++, $jj++) { $jsonValue = false; $attribute = $attributeBase; + $attribute .= Support::doAttribute('name', HelperFormElement::prependFormElementIdCheckBoxMulti($htmlFormElementId, $ii)); // Do this only the first round. if ($flagFirst) { @@ -1114,8 +1115,6 @@ abstract class AbstractBuildForm { $htmlElement = '<input ' . $attribute . '>' . $value; -// $htmlElement = Support::wrapTag("<label class='$orientation'>", $htmlElement, true); -// $htmlElement = Support::wrapTag("<label>", $htmlElement, true); // With ALIGN_HORIZONTAL: the label causes some trouble: skip it if (($orientation === ALIGN_VERTICAL)) { $htmlElement = Support::wrapTag('<label>', $htmlElement); @@ -1123,6 +1122,7 @@ abstract class AbstractBuildForm { $htmlElement = Support::wrapTag("<div class='$checkboxClass'>", $htmlElement, true); + // control orientation if ($formElement['maxLength'] > 1) { if ($jj == $formElement['maxLength']) { diff --git a/extension/qfq/qfq/helper/HelperFormElement.php b/extension/qfq/qfq/helper/HelperFormElement.php index 958c4fcfad24d12fd94f60ad570c7fe9e20b824c..da5cb214d9d733f103d9e476bde56cdf5b6e6c66 100644 --- a/extension/qfq/qfq/helper/HelperFormElement.php +++ b/extension/qfq/qfq/helper/HelperFormElement.php @@ -61,8 +61,8 @@ class HelperFormElement } /** - * @param $field - * @param $id + * @param string $field + * @param string $id * @return string */ public static function buildFormElementId($field, $id) @@ -70,4 +70,13 @@ class HelperFormElement return ($field . ':' . $id); } + /** + * @param string $field + * @param string $index + * @return string + */ + public static function prependFormElementIdCheckBoxMulti($field, $index) { + return ('_' . $index . '_' . $field); + } + } \ No newline at end of file diff --git a/extension/qfq/qfq/store/FillStoreForm.php b/extension/qfq/qfq/store/FillStoreForm.php index 48b66443863d889c239c093104bbabb60a7e111c..6c6514827af01607825c0ce406c05c98c14694b2 100644 --- a/extension/qfq/qfq/store/FillStoreForm.php +++ b/extension/qfq/qfq/store/FillStoreForm.php @@ -130,6 +130,11 @@ class FillStoreForm { continue; } + // Checkbox Multi: collect values + if ($formElement[FE_TYPE] == 'checkbox') { + $clientValues[$clientFieldName] = $this->collectCheckboxMultiValue($clientFieldName, $clientValues); + } + if ($formElement[FE_MODE] === FE_MODE_REQUIRED) { if (!isset($clientValues[$clientFieldName]) || ($clientValues[$clientFieldName] === '')) { throw new UserFormException("Missing required value.", ERROR_REQUIRED_VALUE_EMPTY); @@ -141,7 +146,7 @@ class FillStoreForm { case FE_MODE_SHOW: if (isset($clientValues[$clientFieldName])) { - // SELECT MULTI or CHECKBOX MULTI: delivered as array - implode them. + // CHECKBOX MULTI (SELECT MULTI ?): 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) @@ -177,6 +182,31 @@ class FillStoreForm { $this->store->setVarArray($newValues, STORE_FORM, true); } + /** + * @param $clientFieldName + * @param array $clientValues + * @return mixed + */ + private function collectCheckboxMultiValue($clientFieldName, array $clientValues) { + $checkboxValue = array(); + + $checkboxKey = HelperFormElement::prependFormElementIdCheckBoxMulti($clientFieldName, 'h'); + // Check there is a hidden value with naming in checkbox multi syntax + if (isset($clientValues[$checkboxKey])) { + $checkboxValue[] = $clientValues[$checkboxKey]; + $pattern = '/' . HelperFormElement::prependFormElementIdCheckBoxMulti($clientFieldName, '\d+') . '/'; + foreach ($clientValues as $key => $value) { + if (1 === preg_match($pattern, $key)) { + $checkboxValue[] = $value; + } + } + + $clientValues[$clientFieldName] = $checkboxValue; + } + + return $clientValues[$clientFieldName]; + } + /** * Check $value as date/datime/time value and convert it to FORMAT_DATE_INTERNATIONAL. *