* @package tao */ class tao_helpers_form_xhtml_Form extends tao_helpers_form_Form { use LoggerAwareTrait; // --- ASSOCIATIONS --- // --- ATTRIBUTES --- // --- OPERATIONS --- /** * Short description of method getValues * * @access public * @author Bertrand Chevrier, * @param string $groupName * @param array $filterProperties List of properties which values are unneeded and must be filtered * @return array */ public function getValues($groupName = '') { $returnValue = []; foreach ($this->elements as $element) { if (!empty($this->systemElements) && in_array($element->getName(), $this->systemElements)) { continue; } if ( empty($groupName) || in_array($element->getName(), $this->groups[$groupName]['elements']) ) { $returnValue[tao_helpers_Uri::decode($element->getName())] = $element->getEvaluatedValue(); } } return (array) $returnValue; } /** * Evaluate the form */ public function evaluate() { $this->initElements(); $submitKey = $this->name . '_sent'; if (isset($_POST[$submitKey])) { $this->submited = true; // Set posted values foreach ($this->elements as $id => $element) { $this->elements[$id]->feed(); } $this->validate(); } } /** * Short description of method render * * @access public * @author Bertrand Chevrier, * @return string */ public function render() { $returnValue = ''; $requestUri = $_SERVER['REQUEST_URI'] ?? ''; $action = strpos($requestUri, '?') > 0 ? substr($requestUri, 0, strpos($requestUri, '?')) : $requestUri; // Defensive code, prevent double leading slashes issue. if (strpos($action, '//') === 0) { $action = substr($action, 1); } $returnValue .= "
\n"; $returnValue .= "
hasFileUpload()) { $returnValue .= "enctype='multipart/form-data' "; } $returnValue .= ">\n"; $returnValue .= "\n"; if (!empty($this->error)) { $returnValue .= '
' . $this->error . '
'; } $returnValue .= $this->renderElements(); $returnValue .= $this->renderActions(); $returnValue .= "
\n"; $returnValue .= "
\n"; return $returnValue; } /** * Validate the form * * @author Bertrand Chevrier, * @return bool */ protected function validate() { $returnValue = true; $this->valid = true; /** @var tao_helpers_form_FormElement $element */ foreach ($this->elements as $element) { if (!$element->validate()) { $this->valid = false; } } return $returnValue; } }