private function getPostValue(Unit $unit) { foreach ($this->formSubmit->getPostValues() as $value) { if ($value->getKey() === $unit->getId()) { return $value->getValue(); } } }
public function getSelectField($renderApi, $unit, $fieldId, $postRequestValue = null) { $inputName = strlen($renderApi->getFormValue($unit, 'inputName')) > 0 ? $renderApi->getFormValue($unit, 'inputName') : $fieldId; $formField = new \SelectField(); $formField->getElementProperties()->addAttribute("name", $inputName); $formField->getElementProperties()->addAttribute("id", $fieldId); $listOptions = $this->listOptions->getListOptions($renderApi, $unit); if ($listOptions->hasOptions()) { foreach ($listOptions->getOptions() as $option) { /* @var $option \Option */ $optionField = new \OptionField(); $optionField->setContent($option->getName()); $elementProperties = $optionField->getElementProperties(); $elementProperties->addAttribute("value", $option->getValue()); if (is_null($postRequestValue) && $option->isChecked() || $postRequestValue === $option->getValue()) { $elementProperties->addAttribute("selected", null); } $formField->add($optionField); } } if ($this->formSubmit->isValid($renderApi, $unit) && !$this->isValidValue($unit, $postRequestValue)) { $formField->getElementProperties()->addClass('vf__error'); } return $formField; }
/** * Generate the widget and return it as string * @return string */ public function generate() { if ($this->imageSubmit && $this->singleSRC != '') { parent::generate(); } // Return the regular button as button not input return sprintf('<button type="submit"%s class="submit%s"%s%s<span class="before"></span><span>%s</span><span class="after"></span></button>', $this->strId ? ' id="ctrl_' . $this->strId . '"' : '', $this->strClass != '' ? ' ' . $this->strClass : '', $this->getAttributes(), $this->strTagEnding, specialchars($this->slabel)); }
/** * Parse the template file and return it as string * @param array * @return string */ public function parse($arrAttributes = null) { if ($this->formcontrol_template) { $this->strTemplate = $this->formcontrol_template; $this->type = 'regular'; // Image button if ($this->imageSubmit && $this->singleSRC != '') { $objModel = \FilesModel::findByUuid($this->singleSRC); if ($objModel === null) { if (!\Validator::isUuid($this->singleSRC)) { return '<p class="error">' . $GLOBALS['TL_LANG']['ERR']['version2format'] . '</p>'; } } elseif (is_file(TL_ROOT . '/' . $objModel->path)) { $this->type = 'image'; $this->src = $objModel->path; } } } return parent::parse($arrAttributes); }
/** * Compare the unit form field collection with post values. * * @param $renderApi * @param $unit * * @return boolean false if post values do not contain a unit form field */ private function compareFormUnits($renderApi, $unit) { $result = true; $this->collectUnitFormFields($renderApi, $unit); foreach ($this->formUnits as $formUnit) { $formValues = $formUnit->getFormValues(); // workaround to catch non-required not selected checkboxes if (!isset($formValues['enableRequired']) || !$formValues['enableRequired']) { $found = true; } else { $found = array_filter($this->formSubmit->getPostValues(), function ($postValue) use(&$formUnit) { return $postValue->getKey() === $formUnit->getId(); }); } if (!$found) { $result = false; break; } } return $result; }
<?php header('Content-Type: application/json'); require_once '../model/SimpleTableManager.php'; require_once '../model/FormSubmitManager.php'; $tableManager = new SimpleTableManager(); $errors = array(); // array to hold validation errors $data = array(); // array to pass back data $tableName = FormSubmit::POST("table"); $crudType = FormSubmit::POST("crud-type"); $tableManager = new SimpleTableManager(); $tableManager->Initialize($tableName); $tableManager->debug = true; if (isset($_POST["updateTo"])) { foreach ($_POST["updateTo"] as $key => $value) { $tableManager->{$key} = $value; } } echo json_encode($tableManager->update()); //echo json_encode($tableManager->getTablePrimaryKey())
public function Load($ff, $addendum, $signal) { if (!isfile($ff, 'forms/')) { return; } $file = file_get_contents('forms/' . $ff); $data = new HDataStream($file); $data = $data->toArray(); $settings = array(); $settings['insert'] = array(); $settings['hidden'] = array(); $settings['text'] = array(); $settings['multiline'] = array(); $settings['slider'] = array(); $settings['date'] = array(); $settings['select'] = array(); $settings['radio'] = array(); $settings['submit'] = array(); $settings['list'] = array(); $settings['name'] = 'form'; $settings['action'] = 'ajax.post.php'; if (!is_null($addendum) && is_array($addendum)) { foreach ($addendum as $add => $val) { $settings[$add] = $val; } } if (isset($settings['dbid'])) { $this->dbid = $settings['dbid']; } $t = count($data); $o = 0; for ($i = 0; $i < $t; $i++) { $setting = $data[$i + 1]; if (matches($data[$i], "text")) { $settings['text'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "hidden")) { $settings['hidden'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "multiline") || matches($data[$i], "textarea")) { $settings['multiline'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "slider")) { $settings['slider'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "date")) { $settings['date'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "select")) { $settings['select'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "list")) { $settings['list'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "radio")) { $settings['radio'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "insert")) { $settings['insert'][$o++] = HDataStream::asKV($setting); } else { if (matches($data[$i], "submit")) { $settings['submit'][$o++] = HDataStream::asKV($setting); } else { $settings[$data[$i]] = $setting; } } } } } } } } } } $i++; } $this->form = new FormHelper($settings['name'], $settings['action'], $this->dbid, $signal); for ($i = 0; $i < $o; $i++) { if (isset($settings['radio'][$i])) { $e = $settings['radio'][$i]; $e['html'] = HDataStream::asKV($e['html']); $e['options'] = HDataStream::asKV($e['options']); $element = new FormRadio($e, TRUE); if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) { $element->Set($this->data[$e['data']]); } $element->_Init($element->settings); $this->form->Add($element); } else { if (isset($settings['select'][$i])) { $e = $settings['select'][$i]; $e['html'] = HDataStream::asKV($e['html']); $e['options'] = HDataStream::asKV($e['options']); $element = new FormSelect($e, TRUE); if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) { $element->Set($this->data[$e['data']]); } $element->_Init($element->settings); $this->form->Add($element); } else { if (isset($settings['list'][$i])) { $e = $settings['list'][$i]; $e['html'] = HDataStream::asKV($e['html']); $e['options'] = HDataStream::asKV($e['options']); $element = new FormList($e, TRUE); if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) { $element->Set($this->data[$e['data']]); } $element->_Init($element->settings); $this->form->Add($element); } else { if (isset($settings['slider'][$i])) { $e = $settings['slider'][$i]; $e['html'] = HDataStream::asKV($e['html']); $element = new FormSlider($e, TRUE); if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) { $element->Set($this->data[$e['data']]); } $element->_Init($element->settings); $this->form->Add($element); } else { if (isset($settings['multiline'][$i])) { $e = $settings['multiline'][$i]; $e['html'] = HDataStream::asKV($e['html']); $element = new FormMultiline($e, TRUE); if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) { $element->Set($this->data[$e['data']]); } $element->_Init($element->settings); $this->form->Add($element); } else { if (isset($settings['text'][$i])) { $e = $settings['text'][$i]; $e['html'] = HDataStream::asKV($e['html']); $element = new FormText($e, TRUE); if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) { $element->Set($this->data[$e['data']]); } $element->_Init($element->settings); $this->form->Add($element); } else { if (isset($settings['insert'][$i])) { $e = $settings['insert'][$i]; $this->form->Add(new FormInsert($e)); } else { if (isset($settings['hidden'][$i])) { $e = $settings['insert'][$i]; $this->form->Add(new FormHidden($e)); } else { if (isset($settings['submit'][$i])) { $e = $settings['submit'][$i]; $e['html'] = HDataStream::asKV($e['html']); $element = new FormSubmit($e, TRUE); if (!is_null($this->data) && isset($e['data']) && isset($this->data[$e['data']])) { $element->Set($this->data[$e['data']]); } $element->_Init($element->settings); $this->form->Add($element); } } } } } } } } } } }