Commit 19ced86c authored by Carsten  Rose's avatar Carsten Rose
Browse files

Save.php: elements() simplified by using STORE_FORM.

parent 5605ee52
......@@ -74,15 +74,10 @@ class Save {
*/
public function elements($recordId) {
//TODO: Umstellen auf Nutzung der Klasse FillStoreForm.
$html = '';
$newValues = array();
$tableColumns = array_keys($this->store->getStore(STORE_TABLE_COLUMN_TYPES));
$clientValues = $this->store->getStore(STORE_CLIENT);
// Retrieve SIP vars, e.g. for HIDDEN elements.
$sipValues = $this->store->getStore(STORE_SIP);
$formValues = $this->store->getStore(STORE_FORM);
// Iterate over all table.columns. Built an assoc array $newValues.
foreach ($tableColumns AS $column) {
......@@ -98,34 +93,9 @@ class Save {
// Preparation for Log, Debug
$this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM);
if ($formElement['type'] == 'hidden') {
// Hidden elements will be transferred by SIP
if (!isset($sipValues[$column])) {
throw new CodeException("Missing the hidden field '$column' in SIP.", ERROR_MISSING_HIDDEN_FIELD_IN_SIP);
}
$newValues[$column] = $sipValues[$column];
continue;
}
// construct the field name used in the form
$clientFieldName = HelperFormElement::buildFormElementId($column, $recordId);
if (isset($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]);
}
$newValues[$column] = Sanitize::sanitize($clientValues[$clientFieldName], $formElement['checkType'], $formElement['checkPattern'], SANATIZE_EXCEPTION);
if (isset($formValues[$column])) {
$newValues[$column] = $formValues[$column];
}
}
return ($recordId == 0) ? $this->insertRecord($this->formSpec['tableName'], $newValues) : $this->updateRecord($this->formSpec['tableName'], $newValues, $recordId);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment