mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-18 00:09:06 +01:00
LSform: fix handling default values of dataEntryForm
This commit is contained in:
parent
e23ee2f209
commit
a56b20728a
1 changed files with 21 additions and 7 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue