diff --git a/src/includes/class/class.LSform.php b/src/includes/class/class.LSform.php index 5e96e0b8..48af467c 100644 --- a/src/includes/class/class.LSform.php +++ b/src/includes/class/class.LSform.php @@ -498,11 +498,13 @@ class LSform extends LSlog_staticLoggerClass { } } else { - $elementsList = $this -> dataEntryFormConfig['displayedElements']; - if (isset($this -> dataEntryFormConfig['defaultValues']) && is_array($this -> dataEntryFormConfig['defaultValues'])) { - $this -> setPostData($this -> dataEntryFormConfig['defaultValues']); - $elementsList = array_merge($elementsList,array_keys($this -> dataEntryFormConfig['defaultValues'])); - } + $defaultValues = LSconfig::get( + 'defaultValues', array(), 'array', $this -> dataEntryFormConfig + ); + $elementsList = array_merge( + $this -> dataEntryFormConfig['displayedElements'], + array_keys($this -> dataEntryFormConfig['defaultValues']) + ); foreach($elementsList as $elementName) { if (!isset($this -> elements[$elementName])) { @@ -510,9 +512,21 @@ class LSform extends LSlog_staticLoggerClass { continue; } $element = $this -> elements[$elementName]; - if ((isset($this -> dataEntryFormConfig['requiredAllAttributes']) && $this -> dataEntryFormConfig['requiredAllAttributes']) || isset($this -> dataEntryFormConfig['requiredAttributes']) && is_array($this -> dataEntryFormConfig['requiredAttributes']) && in_array($elementName,$this -> dataEntryFormConfig['requiredAttributes'])) { - $element -> setRequired(); + // Set required from dataEntryForm config + if ( + LSconfig :: get('requiredAllAttributes', false, 'bool', $this -> dataEntryFormConfig) || + in_array( + $elementName, + LSconfig :: get('requiredAttributes', array(), 'array', $this -> dataEntryFormConfig) + ) + ){ + $element -> setRequired(); } + // Set default value if not present in POST data + if (!isset($_POST[$elementName]) && isset($defaultValues[$elementName])) { + $_POST[$elementName] = ensureIsArray($defaultValues[$elementName]); + } + // Retrieve POST data of the element if( !($element -> getPostData($this -> _postData, $onlyIfPresent)) ) { LSerror :: addErrorCode('LSform_02',$element_name); return;