/** * getField() * * 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(); } return sprintf('<input type="email" name="%s" id="%1$s" value="%s" size="%d" %s' . \FormHandler\Configuration::get('xhtml_close') . '>%s', $this->name, htmlspecialchars($this->getValue()), $this->getSize(), (!is_null($this->getMaxLength()) ? 'maxlength="' . $this->getMaxLength() . '" ' : '') . (isset($this->tab_index) ? 'tabindex="' . $this->tab_index . '" ' : '') . (isset($this->extra) ? ' ' . $this->extra . ' ' : '') . ($this->getDisabled() && !$this->getDisabledInExtra() ? 'disabled="disabled" ' : ''), isset($this->extra_after) ? $this->extra_after : ''); }
/** * ColorPicker::getField() * * Return the HTML of the field * * @return string: the html of the field * @author Rick den Haan */ public function getField() { // view mode enabled ? if ($this->getViewMode()) { // get the view value.. return $this->_getViewValue(); } // check if the user set a class if (isset($this->extra) && preg_match("/class *= *('|\")(.*)\$/i", $this->extra)) { // put the function into a onchange tag if set $this->extra = preg_replace("/class *= *('|\")(.*)\$/i", "class=\"color \\2", $this->extra); } else { $this->extra = "class=\"color\"" . (isset($this->extra) ? $this->extra : ''); } $max_length = $this->getMaxLength(); return sprintf('<input type="text" name="%s" id="%1$s" value="%s" size="%d" %s' . \FormHandler\Configuration::get('xhtml_close') . '>%s', $this->name, htmlspecialchars($this->getValue()), $this->getSize(), (!empty($max_length) ? 'maxlength="' . $max_length . '" ' : '') . (isset($this->tab_index) ? 'tabindex="' . $this->tab_index . '" ' : '') . (isset($this->extra) ? ' ' . $this->extra . ' ' : ''), isset($this->extra_after) ? $this->extra_after : ''); }
/** * CheckBox::_getCheckBox() * * Return an option of the checkbox with the given value * * @param string $value the value for the checkbox * @param string $title the title for the checkbox * @param bool $use_mask do we have to use the mask after the field? * @return string the HTML for the checkbox * @author Teye Heimans */ private function getCheckBox($value, $title, $use_mask = false) { static $iCounter = array(); if (!array_key_exists($this->name, $iCounter)) { $iCounter[$this->name] = 1; } $this->maskLoader(); // get the field HTML $mask = trim($title) == '' ? '' : '<label for="%2$s_%3$d" class="noStyle">%s</label>'; //process disabled $disabled_value = $this->getDisabled(); $disabled_global = is_bool($disabled_value) && $disabled_value === true; $disabled_values = is_array($disabled_value) && in_array($value, $disabled_value); $field = sprintf('<input type="checkbox" name="%s" id="%s_%d" value="%s" %s' . \FormHandler\Configuration::get('xhtml_close') . '>' . $mask, $this->name . (is_array($this->getOptions()) ? '[]' : ''), $this->name, $iCounter[$this->name]++, htmlspecialchars($value), (isset($this->tab_index) ? 'tabindex="' . $this->tab_index . '" ' : '') . (in_array($value, $this->getValue()) ? 'checked="checked" ' : '') . (isset($this->extra) ? $this->extra . ' ' : '') . (($disabled_global || $disabled_values) && !$this->getDisabledInExtra() ? 'disabled="disabled" ' : ''), $title); // do we have to use the mask ? if ($use_mask) { $field = $this->loader->fill($field); } return $field; }
/** * Constructor * * Create a select field * * @param FormHandler $form The form where the field is located on * @param string $name The name of the form * @return \FormHandler\Field\Select * @author Teye Heimans * @author Marien den Besten */ public function __construct(FormHandler $form, $name) { // call the constructor of the Field class return parent::__construct($form, $name)->setJsSelectorValue('#' . $form->getFormName() . ' select[name="' . $name . '"]')->setSize(1)->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setMultiple(false); }
/** * Load a specific FH JS library * * Library is the js file name * * @param string $library * @return boolean True when not loaded before */ private function loadJsLibrary($library) { if (!array_key_exists('__FH_JS_' . $library, $GLOBALS)) { $GLOBALS['__FH_JS_' . $library] = true; $this->_setJS(\FormHandler\Configuration::get('fhtml_dir') . 'js/' . $library . '.js', true); return true; } return false; }
/** * 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 : ''); }
/** * Return the HTML of the field * * @return string the html * @author Marien den Besten */ public function getField() { // view mode enabled ? if ($this->getViewMode()) { // get the view value.. return is_array($this->value) && array_key_exists('name') ? $this->value['name'] : ''; } return sprintf('<input type="file" name="%s" id="%1$s" %s' . \FormHandler\Configuration::get('xhtml_close') . '>%s', $this->name, (isset($this->tab_index) ? 'tabindex="' . $this->tab_index . '" ' : '') . (isset($this->extra) ? ' ' . $this->extra . ' ' : '') . ($this->getDisabled() && !$this->getDisabledInExtra() ? 'disabled="disabled" ' : ''), isset($this->extra_after) ? $this->extra_after : ''); }
/** * ImageButton::getButton() * * Return the HTML of the button * * @return string the HTML of the button * @author Teye Heimans */ public function getButton() { // return the button return sprintf('<input type="image" src="%s" name="%s" id="%2$s"%s ' . \FormHandler\Configuration::get('xhtml_close') . '>', $this->image, $this->name, (isset($this->extra) ? ' ' . $this->extra : '') . (isset($this->tab_index) ? ' tabindex="' . $this->tab_index . '"' : '')); }
/** * 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; } }
/** * 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 ''; }
/** * Constructor: create a new Button object * * @param FormHandler $form the form where the button is located on * @param string $name the name of the button * @return static * @author Teye Heimans * @author Marien den Besten */ public function __construct(FormHandler $form, $name) { //set the button name and caption $this->form = $form; $this->name = $name; return $this->setType(self::TYPE_BUTTON)->disableOnSubmit(\FormHandler\Configuration::get('default_disable_submit_btn'))->setFocusName($name); }
/** * Return the HTML of the field * * @return string the html of the field * @author Marien den Besten */ public function getField() { // view mode enabled ? if ($this->getViewMode()) { // get the view value.. return $this->_getViewValue(); } $current_value = $this->getValue(); if (is_null($current_value)) { $this->button_edit->setExtra('style="display:none;"', true); $value = ''; } else { $value = $this->form_object->truncateString($current_value->getFilename()); $this->button_upload->setExtra('style="display:none;"', true); $this->setExtra('style="display:none;"', true); } $status = '<span id="' . $this->name . '_status" class="upload" data-no-upload="No file chosen">' . \FormHandler\Utils::html($value) . '</span>'; $return = $this->token->getField() . $this->filename->getField() . $this->state->getField() . $this->button_edit->getButton() . $this->button_upload->getButton() . $status; //process accept if (count($this->accept) !== 0) { $this->setExtra('accept="' . implode(', ', $this->accept) . '"', true); } $dropzone_start = ''; $dropzone_stop = ''; if ($this->getDropZoneEnabled()) { $dropzone_start = '<span' . ' id="' . $this->name . '_dropzone"' . ' data-drop-here="' . \FormHandler\Utils::html($this->drop_zone_language['drop_file']) . '"' . ' data-too-large="' . \FormHandler\Utils::html($this->drop_zone_language['too_large']) . '"' . ' class="FH_dropzone">'; $dropzone_stop = '</span>'; } //return the field return $dropzone_start . $return . sprintf('<input type="file" name="%s" id="%1$s" %s' . \FormHandler\Configuration::get('xhtml_close') . '>%s', $this->name, (isset($this->tab_index) ? 'tabindex="' . $this->tab_index . '" ' : '') . (isset($this->extra) ? $this->extra . ' ' : '') . ($this->getDisabled() && !$this->getDisabledInExtra() ? 'disabled="disabled" ' : ''), isset($this->extra_after) ? $this->extra_after : '') . $dropzone_stop; }
/** * Hidden::getField() * * Return the HTML of the field * * @return string The html of the field * @author Teye Heimans * @author Marien den Besten */ public function getField() { $value = ''; if (is_array($this->getValue())) { $value = '__FH_JSON__' . htmlspecialchars(json_encode($this->getValue())); } elseif (!is_array($this->getValue())) { $value = htmlspecialchars($this->getValue()); } return sprintf('<input type="hidden" name="%s" id="%1$s" value="%s" %s' . \FormHandler\Configuration::get('xhtml_close') . '>%s', $this->name, $value, isset($this->extra) ? $this->extra . ' ' : '', isset($this->extra_after) ? $this->extra_after : ''); }
/** * Radio::_getRadio() * * Return the radio field with the given title and value * * @param string $value the value for the checkbox * @param string $title the title for the checkbox * @param bool $use_mask Do we need to use the mask ? * @return string the HTML for the checkbox * @author Teye Heimans */ private function getRadio($value, $title, $use_mask = false) { static $counter = 1; $value = trim($value); if (is_null($this->loader)) { $this->loader = new MaskLoader(); $this->loader->setMask($this->mask); $this->loader->setSearch('/%field%/'); } $field = sprintf('<input type="radio" name="%s" id="%1$s_%d" value="%s" %s' . \FormHandler\Configuration::get('xhtml_close') . '>' . '<label for="%1$s_%2$d" class="noStyle">%s</label>', $this->name, $counter++, htmlspecialchars($value), ($value == $this->getValue() ? 'checked="checked" ' : '') . (isset($this->tab_index) ? 'tabindex="' . $this->tab_index . '" ' : '') . (!empty($this->extra) ? $this->extra . ' ' : '') . ($this->getDisabled() && !$this->getDisabledInExtra() ? 'disabled="disabled" ' : ''), trim($title)); // do we have to use the mask ? if ($use_mask) { $field = $this->loader->fill($field); } return $field; }
/** * getField() * * Return the HTML of the field * * @return string the html * @author Marien den Besten * @author Ruben de Vos */ public function getField() { // view mode enabled ? if ($this->getViewMode()) { // get the view value.. return $this->_getViewValue(); } if (is_null($this->getValue())) { $this->empty->setValue(1); $this->setDisabled(true); $this->empty->setDisabled(false); } return sprintf('<input type="number" name="%s" id="%1$s" value="%s" %s' . \FormHandler\Configuration::get('xhtml_close') . '>%s', $this->name, htmlspecialchars($this->getValue()), (!is_null($this->min) ? 'min="' . $this->min . '" ' : '') . (!is_null($this->max) ? 'max="' . $this->max . '" ' : '') . (!is_null($this->step) ? 'step="' . $this->step . '" ' : '') . (isset($this->tab_index) ? 'tabindex="' . $this->tab_index . '" ' : '') . (isset($this->extra) ? ' ' . $this->extra . ' ' : '') . ($this->getDisabled() && !$this->getDisabledInExtra() ? 'disabled="disabled" ' : ''), isset($this->extra_after) ? $this->extra_after : '') . ($this->allow_empty === true ? '<div class="number-field-unknown">' . $this->empty->getField() . '</div>' : ''); }