Ejemplo n.º 1
0
 /**
  * Get view value
  * @return string
  */
 public function _getViewValue()
 {
     $v = \FormHandler\Utils::html($this->getValue());
     if ($this->getEnableViewModeLink() && trim($v) != '') {
         $this->setViewModeLink('mailto:' . $v);
     }
     return parent::_getViewValue();
 }
Ejemplo n.º 2
0
 public function setValidator($validator = null)
 {
     if (count($this->getValidators()) === 0 && $validator instanceof FormHandler\Validator\FunctionCallable && is_array($validator->getCallable())) {
         $callable = $validator->getCallable();
         //detect if it is an optional validator
         if ($callable[0] instanceof Validator && substr($callable[1], 0, 1) !== '_') {
             parent::setValidator(new \FormHandler\Validator\NotEmpty());
         }
     }
     return parent::setValidator(FormHandler::parseValidator($validator, $this));
 }
Ejemplo n.º 3
0
 /**
  * ColorPicker::ColorPicker()
  *
  * Constructor: Create a new ColorPicker object
  *
  * @param object $form The form where this field is located on
  * @param string $name The name of the field
  * @return \FormHandler\Field\ColorPicker
  * @author Rick den Haan
  */
 public function __construct($form, $name)
 {
     parent::__construct($form, $name);
     static $bSetJS = false;
     // needed javascript included yet ?
     if (!$bSetJS) {
         // include the needed javascript
         $bSetJS = true;
         $form->_setJS(\FormHandler\Configuration::get('fhtml_dir') . "js/jscolor/jscolor.js", true);
     }
     return $this;
 }
Ejemplo n.º 4
0
 *
 * 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;
});
$form_html = $form->flush();
echo '<!DOCTYPE html>' . '<html><head>' . '<style>' . '.FH_dropzone span.upload' . '{' . 'display:block;' . '}' . '.FH_dropzone' . '{' . 'width:250px;' . 'padding:30px;' . 'display:inline-block;' . 'border:3px dashed #CCC;' . '}' . '.FH_dropzone.dragover' . '{' . 'border-color:#000;' . 'background-color:#EEE;' . '}' . '</style>' . '</head><body>' . 'Test for upload field<hr>' . $form_html . '</body></html>';
Ejemplo n.º 5
0
 * 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();
for ($i = 1; $i <= 15; $i++) {
    Field\Text::set($form, 'Field ' . $i, 'field_' . $i)->setValue('Value ' . $i);
}
$form->getField('field_1')->hideFromOnCorrect();
$form->getField('field_3')->hideFromOnCorrect();
$form->getField('field_5')->hideFromOnCorrect();
$form->getField('field_7')->hideFromOnCorrect();
$form->onCorrect(function ($data) {
    echo '<pre>Field 1, 3, 5, 7 should be hidden from results' . "\n";
    print_r($data);
    echo '</pre>';
    exit;
});
Button\Submit::set($form, 'Press submit to see if the oncorrect data works');
//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
Ejemplo n.º 6
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 Ruben de Vos
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
//create a new FormHandler object
$form = new FormHandler();
//some fields.. (see manual for examples)
Field\Text::set($form, 'Name', 'name')->setValidator(new Validator\String())->setMaxlength(40);
Field\ColorPicker::set($form, 'Color', 'color');
//button for submitting
Button\Submit::set($form, 'Send');
//set the 'commit-after-form' function
$form->onCorrect(function ($data) {
    return "Hello " . $data['name'] . ", you picked the color " . $data['color'] . "!";
});
//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 'Color Picker demo<hr>';
echo $form_html;
Ejemplo n.º 7
0
 * 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();
for ($i = 1; $i <= 15; $i++) {
    Field\Text::set($form, 'Field ' . $i, 'field_' . $i);
}
Field\Text::set($form, 'Insert before 5', 'before_five')->insertBefore('field_5');
Field\Text::set($form, 'Insert after 6', 'after_six')->insertAfter('field_6');
Field\Text::set($form, 'Move before 1', 'before_1');
$form->moveFieldBefore('field_1', 'before_1');
Field\Text::set($form, 'Move after 15', 'after_15');
$form->moveFieldAfter('field_15', 'after_15');
//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 moving fields after definition<hr>';
echo $form_html;
 * 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
 *
 * @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/');
echo 'Test for multi link view mode';
echo '<hr>';
$form = new FormHandler();
Field\Text::set($form, 'Single value', 'field1')->setViewMode()->setValue('VALUE')->setViewModeLink('startofurl?value={$value}&extra=1');
Field\Select::set($form, 'Multi value', 'field2')->setViewMode()->setValue(array(1, 2))->setOptions(array(1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'))->setViewModeLink('startofurl?value={$value}&extra=1');
//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 view mode links with one or multiple values set<hr>';
echo $form_html;
Ejemplo n.º 9
0
 /**
  * FormHandler::jsdateTextField()
  *
  * Create a dateTextField on the form
  * Validator added by Johan Wiegel
  *
  * @param string $title The title of the field
  * @param string $name The name of the field
  * @param string $validator
  * @param string $mask How do we have to display the fields? These can be used: d, m and y. (Only for DB-Field with Type 'Date')
  * @param bool $bParseOtherPresentations try to parse other presentations of dateformat
  * @param boolean $bIncludeJS Should we include the js file (only needed once on a page)
  * @param string $extra CSS, Javascript or other which are inserted into the HTML tag
  * @param boolean $bIncludeJS Should we include the js file (only needed once on a page)
  * @return \FormHandler\Field\Text
  * @author Thomas Branius
  * @since 16-03-2010
  * @deprecated No alternative exist yet
  */
 public function jsDateTextField($title, $name, $validator = null, $mask = null, $bParseOtherPresentations = false, $extra = null, $bIncludeJS = true)
 {
     $field = \FormHandler\Field\Text::set($this, $title, $name);
     return $field->setValidator(self::parseValidator($validator, $field))->setExtra($extra);
 }
Ejemplo n.º 10
0
 * 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;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
$form = new FormHandler();
Field\CheckBox::set($form, '', 'inherit')->setOptions(array(1 => 'Inherit from parent, integer value'));
Field\CheckBox::set($form, '', 'inherit1')->setOptions(array(1 => 'Linked to above'));
Field\CheckBox::set($form, '', 'inherit3')->setOptions(array('1' => 'Linked to first checkbox, string value'))->setDisabled();
Field\CheckBox::set($form, 'Multi values<br>', 'inherit4')->setOptions(array(1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'))->setValue(2, true, true);
Field\Text::set($form, 'Linked to first checkbox', 'inherit2');
$link = function ($v) {
    $value = !empty($v);
    return \FormHandler\FormHandler::returnDynamic(array($value), null, null, null, 'checkbox');
};
$form->link('inherit', 'inherit1', $link);
$form->link('inherit', 'inherit3', $link);
$form->link('inherit', 'inherit4', $link);
$form->link('inherit', 'inherit2', function ($v) {
    return \FormHandler\FormHandler::returnDynamic(json_encode($v), null, null, null, 'text');
});
//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 linking checkboxes<hr>';
echo $form_html;
Ejemplo n.º 11
0
 /**
  * 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();
 }
Ejemplo n.º 12
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 Ruben de Vos
 */
include '../src/Loader.php';
use FormHandler\FormHandler;
use FormHandler\Field;
use FormHandler\Button;
use FormHandler\Validator;
\FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/');
//create a new FormHandler object
$form = new FormHandler();
//some fields.. (see manual for examples)
Field\Text::set($form, 'Name', 'name')->setValidator(new Validator\String())->setMaxlength(40)->setHelp('Help text', 'Help title');
Field\Number::set($form, 'Age', 'age')->setValidator(new Validator\Integer())->setMin(1)->setMax(110)->setStep(1)->setHelp('Help text without title');
//button for submitting
Button\Submit::set($form, 'Send');
//set the 'commit-after-form' function
$form->onCorrect(function ($data) {
    return "Hello " . $data['name'] . ", you are " . $data['age'] . " years old!";
});
//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 the help icon<hr>';
echo $form_html;
Ejemplo n.º 13
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/');
//create a new FormHandler object
$form = new FormHandler();
//some fields.. (see manual for examples)
Field\Text::set($form, 'Name', 'name')->setRequired(true)->setMaxlength(40);
Field\Number::set($form, 'Age', 'age')->setRequired(true)->setValidator(new Validator\Integer())->setMin(1)->setMax(110)->setStep(1);
//button for submitting
Button\Submit::set($form, 'Send');
//set the 'commit-after-form' function
$form->onCorrect(function ($data) {
    return "Hello " . $data['name'] . ", you are " . $data['age'] . " years old!";
});
//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 'Basic FormHandler demo<hr>';
echo $form_html;
Ejemplo n.º 14
0
 * 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
 *
 * @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\Select::set($form, 'Multi value 1', 'watch1')->setOptions(array(1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'));
Field\Select::set($form, 'Multi value 2', 'watch2')->setOptions(array(1 => 'Value 1', 2 => 'Value 2', 3 => 'Value 3'));
for ($i = 1; $i <= 20; $i++) {
    Field\Text::set($form, 'Field ' . $i, 'field_' . $i)->setValue('Value ' . $i)->setAppearanceCondition(array('watch1', 'watch2'), function ($value) {
        return $value['watch2'] == 2;
    });
}
//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 grouping multi appearance. Setting multi value 2 on value 2 should display all fields, with one ajax request<hr>';
echo $form_html;