public function validate($bsn) { // remove dots and spaces $bsn = str_replace(array('.', ',', ' '), '', trim($bsn)); // Only numbers are allowed if (!is_numeric($bsn)) { $this->setMessage(\FormHandler\Language::get(45)); return false; } // Remove preceding zeroes while (substr($bsn, 0, 1) == '0' && strlen($bsn > 0)) { $bsn = substr($bsn, 1); } if (strlen($bsn) > 9 or strlen($bsn) < 8) { $this->setMessage(\FormHandler\Language::get(46)); return false; } $res = 0; $verm = strlen($bsn); for ($i = 0; $i < strlen($bsn); $i++, $verm--) { if ($verm == 1) { $verm = -1; } $res += substr($bsn, $i, 1) * $verm; } if ($res % 11 == 0) { return true; } $this->setMessage(\FormHandler\Language::get(47)); return false; }
/** * Get the button * * @author Marien den Besten * @return string */ public function getButton() { $this->extra .= ' onclick="' . (is_null($this->url) ? 'history.back(-1)' : 'document.location.href=\'' . \FormHandler\Utils::url($this->url) . '\'') . '"'; if (is_null($this->caption)) { $this->caption = \FormHandler\Language::get(28); } return parent::getButton(); }
/** * Is field valid * * @return \FormHandler\Field\FileBasic * @author Marien den Besten */ public function processValidators() { $this->setErrorState(false); // when no file field was submitted (on multi-paged forms) if (!isset($_FILES[$this->name])) { return $this; } // is a own error handler used? if (count($this->validators) != 0) { parent::processValidators(); return $this; } // easy name to work with (this is the $_FILES['xxx'] array ) $file = $this->value; if ($this->getRequired() === true && (!is_array($file) || trim($file['name']) == '')) { //no file uploaded $this->setErrorMessage(\FormHandler\Language::get(22)); $this->setErrorState(true); } return $this; }
/** * Process help string for a given field * * @param string $field * @return string * @author Marien den Besten */ private function processHelp($field) { $fld = $this->getField($field); if (is_null($fld) || !method_exists($fld, 'getHelp')) { return ''; } list($text, $title) = $fld->getHelp(); if (is_null($text)) { return ''; } $field_title = $this->getTitle($field); // escape the values from dangerous characters $title = is_null($title) ? $field_title . ' - ' . \FormHandler\Language::get(41) : \FormHandler\Utils::html($title, ENT_NOQUOTES | ENT_IGNORE); return str_replace(array('%helptext%', '%helptitle%', '%helpid%'), array($text, $title, $field . '_help'), Configuration::get('help_mask')); }
/** * Return the HTML of the field * * @return string The html * @author Teye Heimans */ public function getField() { // view mode enabled ? if ($this->getViewMode()) { // get the view value.. return $this->_getViewValue(); } // get the selected and unselected values $current = !is_array($this->getValue()) ? array($this->getValue()) : $this->getValue(); $aSelected = array(); $aUnselected = array(); foreach ($this->getOptions() as $iIndex => $sValue) { $sKey = !$this->getUseArrayKeyAsValue() ? $sValue : $iIndex; if (in_array($sKey, $current)) { $aSelected[$iIndex] = $sValue; } else { $aUnselected[$iIndex] = $sValue; } } $this->field_on->setOptions($aSelected); $this->field_off->setOptions($aUnselected); // add the double click event $this->field_on->extra .= " ondblclick=\"changeValue('" . $this->name . "', false)\""; $this->field_off->extra .= " ondblclick=\"changeValue('" . $this->name . "', true)\""; $mask = !empty($this->vertical_mode) && $this->vertical_mode ? \FormHandler\Configuration::get('listfield_vertical_mask') : \FormHandler\Configuration::get('listfield_horizontal_mask'); return $this->field_values->getField() . "\n" . str_replace(array('%onlabel%', '%offlabel%', '%onfield%', '%offfield%', '%name%', '%ontitle%', '%offtitle%'), array($this->field_on_title, $this->field_off_title, $this->field_on->getField(), $this->field_off->getField(), $this->name, sprintf(\FormHandler\Language::get(34), \FormHandler\Utils::html(strip_tags($this->field_off_title))), sprintf(\FormHandler\Language::get(34), \FormHandler\Utils::html(strip_tags($this->field_on_title)))), $mask) . (isset($this->extra_after) ? $this->extra_after : ''); }
/** * Message to display when validation went wrong * * @return string */ public function getMessage() { return !empty($this->message) ? $this->message : \FormHandler\Language::get(14); }
/** * Constructor: The constructor to create a new Submit object. * * @param object $form the form where this field is located on * @param string $name the name of the button * @return \FormHandler\Button\Submit * @author Teye Heimans */ public function __construct($form, $name) { return parent::__construct($form, $name)->setType(self::TYPE_SUBMIT)->setCaption(\FormHandler\Language::get(26)); }
/** * Check the minlength of the field * * @param integer $iLength the maxlength * @return boolean * @author Johan Wiegel * @since 17-04-2009 */ public function checkMinLength($iLength) { if (strlen($this->getValue()) < $iLength) { $this->error = \FormHandler\Language::get(14); return false; } return true; }
/** * Password::checkPassword() * * Check the value of this field with another password field * * @param \FormHandler\Field\Password $object * @return boolean true if the values are correct, false if not * @author Teye Heimans */ public function checkPassword($object) { // if the fields doesn't match if ($this->getValue() != $object->getValue()) { $this->setErrorMessage(\FormHandler\Language::get(15)); $this->setErrorState(true); return; } // when there is no value if ($this->getValue() == '' && !$this->form_object->edit) { $this->setErrorMessage(\FormHandler\Language::get(16)); $this->setErrorState(true); return; } elseif ($this->getValue() == '') { //in edit mode and value is empty return; } $validator = new Validator\Password(); // is the password not to short ? if (strlen($this->getValue()) < \FormHandler\Configuration::get('min_password_length')) { $this->setErrorMessage(sprintf(\FormHandler\Language::get(17), \FormHandler\Configuration::get('min_password_length'))); $this->setErrorState(true); return; } elseif (!$validator->validate($this->getValue())) { $this->setErrorMessage(\FormHandler\Language::get(18)); $this->setErrorState(true); return; } }
/** * TextArea::getField() * * Return the HTML of the field * * @return string the html of the field * @author Teye Heimans */ public function getField() { // view mode enabled ? if ($this->getViewMode()) { // get the view value.. return $this->_getViewValue(); } // is a limit set ? if (!is_null($this->max_length) && $this->max_length > 0) { // the message $message = \FormHandler\Language::get(36); // set the event $this->extra .= sprintf(" onkeyup=\"displayLimit('%s', '%s', %d, %s, '%s');\"", $this->form_object->getFormName(), $this->name, $this->max_length, $this->show_message ? 'true' : 'false', htmlspecialchars($message)); // should the message be displayed ? if ($this->show_message) { // add the javascript to the fields "extra" argument $this->setExtraAfter("<div id='" . $this->name . "_limit'></div>\n"); } // make sure that when the page is loaded, the message is displayed $this->form_object->_setJS(sprintf("displayLimit('%s', '%s', %d, %s, '%s');\n", $this->form_object->getFormName(), $this->name, $this->max_length, $this->show_message ? 'true' : 'false', $message), false, false); } // return the field return sprintf('<textarea name="%s" id="%1$s" cols="%d" rows="%d"%s>%s</textarea>%s', $this->name, is_null($this->columns) ? 40 : $this->columns, is_null($this->rows) ? 7 : $this->rows, (isset($this->tab_index) ? ' tabindex="' . $this->tab_index . '" ' : '') . (isset($this->extra) ? ' ' . $this->extra : '') . ($this->getDisabled() && !$this->getDisabledInExtra() ? 'disabled="disabled" ' : ''), htmlspecialchars($this->getValue()), isset($this->extra_after) ? $this->extra_after : ''); }
/** * Extend or update the FormHandler language list * * @param integer $index * @param string $string * @deprecated since version 4 * @see \FormHandler\Language::remove() */ public static function languageExclusionUnset($index) { return \FormHandler\Language::remove($index); }
/** * Return the HTML of the field * * @return string the html * @author Teye Heimans */ public function getField() { // empty the field if the value was not correct. if ($this->form_object->isPosted() && !$this->form_object->isCorrect()) { $this->setValue('', true); } // view mode enabled ? if ($this->getViewMode()) { // get the view value.. return ''; } $session_id = \session_id(); //get url from configuration $configured_url = \FormHandler\Configuration::get('securimage_url'); $url = is_null($configured_url) ? \FormHandler\Configuration::get('fhtml_dir') . 'securimage/securimage_show.php' : $configured_url; $url .= '?sid=' . md5(uniqid(time())) . '&session_id=' . $session_id . '&width=' . $this->width . '&height=' . $this->height . '&length=' . $this->getSize(); $this->image->setImage($url); $refresh_text = \FormHandler\Language::get(44); $current_url = @htmlspecialchars($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], ENT_COMPAT, 'UTF-8'); $refresh = '<a id="captcha_refresh" href="//' . $current_url . '" onclick="document.getElementById(\'' . $this->getName() . '_image\').src=\'' . $url . '\'; return false;">' . $refresh_text . '</a>'; return $this->image->getButton() . "<br>" . $refresh . "<br>" . parent::getField(); }
/** * Field::getError() * * Return the error of the field (if the field-value is not valid) * * @return string the error message * @author Teye Heimans */ public function getErrorMessage() { if (isset($this->error)) { if ($this->error === false) { $this->error = \FormHandler\Language::get(14); } if (strlen($this->error) > 0) { return sprintf(\FormHandler\Configuration::get('error_mask'), $this->name, $this->error); } } return ''; }