* * 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>';
* 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 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/'); $form = new FormHandler(); $form->addLine('Button with confirmation on click', true); Button\Submit::set($form, 'Button 1', 'btn_1'); Button\Submit::set($form, 'Button 2', 'btn_2'); Button\Submit::set($form, 'Button 3', 'btn_3'); $form->onCorrect(function ($data, FormHandler $form) { return 'Button "' . $form->getButtonClicked() . '" 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 reading out which button has been click in the onCorrect<hr>'; echo $form_html;
* 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 echo 'Test for hiding fields from the onCorrect function<hr>'; echo $form_html;
<?php /** * Copyright (C) 2016 Ruben de Vos <*****@*****.**>. * * 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 */ include '../src/Loader.php'; \FormHandler\Configuration::set('fhtml_dir', '../src/FHTML/'); $form = new FormHandler\FormHandler(); $field = FormHandler\Field\Percentage::set($form, 'Number', 'length')->setValidator(new \FormHandler\Validator\Integer())->setRequired(true)->allowEmpty(true); $field->setEmptyText('FAIL'); \FormHandler\Button\Submit::set($form); $html = $form->flush(); echo 'Test for number field with option to set unknown<hr>'; echo $html;
* 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;
/** * FormHandler::submitButton() * * Create a submitButton on the form * * @param string $caption The caption of the button * @param string $name The name of the button * @param string $extra CSS, Javascript or other which are inserted into the HTML tag * @param boolean $disableOnSubmit Disable the button when it is pressed * @return \FormHandler\Button\Submit * @author Teye Heimans * @deprecated Use \FormHandler\Button\Submit::set() instead */ public function submitButton($caption = null, $name = null, $extra = null, $disableOnSubmit = null) { $btn = \FormHandler\Button\Submit::set($this, $caption, $name)->setExtra($extra); if (!is_null($disableOnSubmit)) { $btn->disableOnSubmit($disableOnSubmit); } return $btn; }
* 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 */ session_start(); 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(); $form->addLine('Fill captcha', true); Field\Captcha::set($form, 'Required captcha', 'captcha'); $form->onCorrect(function ($data) { echo 'Captcha field working!'; }); Button\Submit::set($form); //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 captcha field<hr>'; echo $form_html;
* 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;