コード例 #1
0
ファイル: Email.php プロジェクト: FormHandler/FormHandler
 /**
  * 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 : '');
 }
コード例 #2
0
 /**
  * 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 : '');
 }
コード例 #3
0
 /**
  * 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 : '');
 }
コード例 #4
0
<?php

/* 
 * Copyright (C) 2015 Marien <*****@*****.**>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */
require_once '..' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Configuration.php';
echo 'Framework default configuration<hr>';
echo '<pre>';
var_dump(\FormHandler\Configuration::getAll());
コード例 #5
0
ファイル: FileBasic.php プロジェクト: FormHandler/FormHandler
 /**
  * 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 : '');
 }
コード例 #6
0
ファイル: Image.php プロジェクト: FormHandler/FormHandler
 /**
  * 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 . '"' : ''));
 }
コード例 #7
0
ファイル: Radio.php プロジェクト: FormHandler/FormHandler
 /**
  * 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;
 }
コード例 #8
0
ファイル: CheckBox.php プロジェクト: FormHandler/FormHandler
 /**
  * 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;
 }
コード例 #9
0
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 *
 * @author Marien den Besten
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
\FormHandler\Configuration::set('default_disable_submit_btn', true);
$form = new FormHandler();
for ($i = 1; $i <= 15; $i++) {
    Field\Text::set($form, 'Field ' . $i, 'field_' . $i)->setDefaultValue('Value ' . $i);
}
Button\Submit::set($form, 'Submit 1')->onClick(function () {
    echo 'Submit 1 clicked';
});
Button\Submit::set($form, 'Submit 2')->onClick(function () {
    echo 'Submit 2 clicked';
});
//process all form results, needs to be done before any output has been done
$form_html = $form->flush();
//below is code to show the form
echo 'Test for disabled buttons on submit<hr>';
echo $form_html;
コード例 #10
0
ファイル: Field.php プロジェクト: FormHandler/FormHandler
 /**
  * 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 '';
 }
コード例 #11
0
ファイル: Button.php プロジェクト: FormHandler/FormHandler
 /**
  * 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);
 }
コード例 #12
0
ファイル: File.php プロジェクト: FormHandler/FormHandler
 /**
  * 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;
 }
コード例 #13
0
ファイル: Hidden.php プロジェクト: FormHandler/FormHandler
 /**
  * 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 : '');
 }
コード例 #14
0
 /**
  * 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;
 }
コード例 #15
0
ファイル: Captcha.php プロジェクト: formhandler/formhandler
 /**
  * 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();
 }
コード例 #16
0
ファイル: Select.php プロジェクト: FormHandler/FormHandler
 /**
  * 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);
 }
コード例 #17
0
ファイル: Password.php プロジェクト: FormHandler/FormHandler
 /**
  * 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;
     }
 }
コード例 #18
0
ファイル: upload.php プロジェクト: FormHandler/FormHandler
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 *
 * @author Marien den Besten
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
$form = new FormHandler();
Field\File::set($form, 'Upload file', 'upload_file')->setDropZoneEnabled(true, 'Drop your custom file here');
Field\Text::set($form, 'Text field', 'some_other_field')->setValidator(new Validator\String());
$form->_setJS('FormHandler.registerHandlerUploaded(\'upload_file\', function(){ alert(\'File uploaded\'); });', false, true);
Button\Submit::set($form, 'Submit 1');
$form->onCorrect(function ($data) {
    echo '<pre>';
    var_dump($_POST);
    var_dump($data);
    if (is_object($data['upload_file'])) {
        echo "\n" . $data['upload_file']->getRealpath();
    }
    echo '</pre>';
    return true;
});
コード例 #19
0
ファイル: Number.php プロジェクト: FormHandler/FormHandler
 /**
  * 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>' : '');
 }