/** * Checks a submitted form. Returns true on success, an (X)HTML error message * on failure. * * @return mixed */ public function validate() { $o = ''; foreach ($this->form->getFields() as $field) { $o .= $this->validateField(Field::make($field)); } if ($this->form->hasCaptcha() && !$this->isCaptchaCorrect()) { $o .= '<li>' . $this->l10n['error_captcha_code'] . '</li>' . PHP_EOL; Controller::focusField($this->form->getName(), 'advancedform-captcha'); } return $o == '' ? true : '<ul class="advfrm-error">' . PHP_EOL . $o . '</ul>' . PHP_EOL; }
/** * Returns the default view of the form. * * @return string (X)HTML. * * @global array The configuration of the plugins. */ protected function renderDefault() { global $plugin_cf; $pcf = $plugin_cf['advancedform']; $o = ''; $o .= '<div style="overflow:auto">' . PHP_EOL . '<table>' . PHP_EOL; foreach ($this->form->getFields() as $field) { $field = Field::make($field); $label = XH_hsc($field->getLabel('label')); $label = $field->isRequired() ? sprintf($pcf['required_field_mark'], $label) : $label; $hidden = $field->getType() == 'hidden'; $class = $hidden ? ' class="hidden"' : ''; $field_id = 'advfrm-' . $this->form->getName() . '-' . $field->getName(); $labelled = !in_array($field->getType(), array('checkbox', 'radio', 'output')); $o .= '<tr' . $class . '>'; if (!$hidden) { $o .= '<td class="label">' . ($labelled ? '<label for="' . $field_id . '">' : '') . $label . ($labelled ? '</label>' : '') . '</td>'; } else { $o .= '<td></td>'; } $o .= '<td class="field">'; $fieldView = new FieldView($this->form->getName(), $field); $o .= $fieldView->render(); $o .= '</td></tr>' . PHP_EOL; if ($labelled && $pcf['focus_form']) { Controller::focusField($this->form->getName(), 'advfrm-' . $field->getName()); } } $o .= '</table>' . PHP_EOL . '</div>' . PHP_EOL; return $o; }
/** * Validates a filled in field wrt. custom constraints. * * @return string (X)HTML. */ protected function validateFilledInFieldCustom() { $o = ''; if (function_exists('advfrm_custom_valid_field')) { $value = $this->field->getType() == 'file' ? $_FILES[$this->name] : stsl($_POST[$this->name]); $valid = advfrm_custom_valid_field($this->formId, $this->field->getName(), $value); if ($valid !== true) { $o .= '<li>' . $valid . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); } } return $o; }