/** * Renders a non select field. * * @return string (X)HTML. */ protected function renderNonSelectField() { $o = ''; if (function_exists('advfrm_custom_field_default')) { $val = advfrm_custom_field_default($this->form, $this->field->getName(), null, isset($_POST['advfrm'])); } if (!isset($val)) { $val = isset($_POST[$this->name]) ? stsl($_POST[$this->name]) : $this->field->getDefaultValue(); } if ($this->field->getType() == 'textarea') { $cols = $this->field->getColumnCount() ? $this->field->getColumnCount() : 40; $rows = $this->field->getRowCount() ? $this->field->getRowCount() : 4; $o .= '<textarea id="' . $this->id . '" name="' . $this->name . '" cols="' . $cols . '" rows="' . $rows . '">' . XH_hsc($val) . '</textarea>'; } elseif ($this->field->getType() == 'output') { $o .= $val; } else { if ($this->field->getType() == 'date') { $this->initDatePicker(); } $size = $this->field->getType() == 'hidden' || $this->field->getSize() ? ' size="' . $this->field->getSize() . '"' : ''; $maxlen = in_array($this->field->getType(), array('hidden', 'file')) || !$this->field->getMaxLength() ? '' : ' maxlength="' . $this->field->getMaxLength() . '"'; if ($this->field->getType() == 'file' && $this->field->getMaxLength()) { $o .= tag('input type="hidden" name="MAX_FILE_SIZE" value="' . $this->field->getMaxLength() . '"'); } if ($this->field->getType() == 'file') { $value = ''; $accept = ' accept="' . XH_hsc($this->prefixFileExtensionList($val)) . '"'; } else { $value = ' value="' . XH_hsc($val) . '"'; $accept = ''; } $o .= tag('input type="' . $this->getInputElementType() . '" id="' . $this->id . '" name="' . $this->name . '"' . $value . $accept . $size . $maxlen); } return $o; }
/** * Validates a filled in field. * * @return string (X)HTML. */ protected function validateFilledInField() { $o = ''; switch ($this->field->getType()) { case 'from': case 'mail': if (!preg_match($this->config['mail_regexp'], stsl($_POST[$this->name]))) { $o .= '<li>' . sprintf($this->l10n['error_invalid_email'], XH_hsc($this->field->getLabel())) . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); } break; case 'date': $pattern = '/^([0-9]+)\\' . $this->l10n['date_delimiter'] . '([0-9]+)\\' . $this->l10n['date_delimiter'] . '([0-9]+)$/'; $matched = preg_match($pattern, stsl($_POST[$this->name]), $matches); if (count($matches) == 4) { $month = $matches[strpos($this->l10n['date_order'], 'm') + 1]; $day = $matches[strpos($this->l10n['date_order'], 'd') + 1]; $year = $matches[strpos($this->l10n['date_order'], 'y') + 1]; } if (!$matched || !checkdate($month, $day, $year)) { $o .= '<li>' . sprintf($this->l10n['error_invalid_date'], XH_hsc($this->field->getLabel())) . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); } break; case 'number': if (!ctype_digit(stsl($_POST[$this->name]))) { $o .= '<li>' . sprintf($this->l10n['error_invalid_number'], XH_hsc($this->field->getLabel())) . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); } break; case 'file': switch ($_FILES[$this->name]['error']) { case UPLOAD_ERR_OK: if ($this->field->getMaxLength() && $_FILES[$this->name]['size'] > $this->field->getMaxLength()) { $o .= '<li>' . sprintf($this->l10n['error_upload_too_large'], XH_hsc($this->field->getLabel())) . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); } break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $o .= '<li>' . sprintf($this->l10n['error_upload_too_large'], XH_hsc($this->field->getLabel())) . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); break; default: $o .= '<li>' . sprintf($this->l10n['error_upload_general'], XH_hsc($this->field->getLabel())) . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); } $ext = pathinfo($_FILES[$this->name]['name'], PATHINFO_EXTENSION); if ($this->field->getFileTypes() != '' && !in_array($ext, explode(',', $this->field->getFileTypes()))) { $o .= '<li>' . sprintf($this->l10n['error_upload_illegal_ftype'], XH_hsc($this->field->getLabel()), XH_hsc($ext)) . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); } break; case 'custom': $pattern = $this->field->getConstraint(); if (!empty($pattern) && !preg_match($pattern, stsl($_POST[$this->name]))) { $msg = $this->field->getErrorMessage() != '' ? $this->field->getErrorMessage() : $this->l10n['error_invalid_custom']; $o .= '<li>' . sprintf($msg, $this->field->getLabel()) . '</li>' . PHP_EOL; Controller::focusField($this->formId, $this->name); } } return $o; }