/** * Register the field with FormHandler * * @param FormHandler $form * @param string|null $caption * @param string|null $name * @param mixed $validator * @return static Instance of */ public static function set(FormHandler $form, $caption = null, $name = null) { $class = get_called_class(); $processed_name = empty($name) ? $form->getNewButtonName() : $name; // create the field $fld = new $class($form, $processed_name); $fld->setCaption($caption); // register the field $form->registerField($processed_name, $fld); return $fld; }
/** * CheckBox::CheckBox() * * Constructor: Create a new checkbox object * * @param FormHandler $form The form where this field is located on * @param string $name The name of the field * @param mixed array|string $options - The options for the field * @return \FormHandler\Field\CheckBox * @author Teye Heimans */ public function __construct(FormHandler $form, $name, $options = array()) { $this->setDefaultValue(array()); $this->value = array(); $this->value_forced = array(); $this->value_default = array(); $nameClean = str_replace('[]', '', $name); //when no checkboxes are selected no data is posted if ($form->isPosted() && !isset($_POST[$nameClean])) { $this->value_post = array(); } // call the constructor of the Field class return parent::__construct($form, $nameClean)->setJsSelectorValue('#' . $form->getFormName() . ' input[name="' . $nameClean . '\\[\\]"]')->setOptions($options)->setMask(\FormHandler\Configuration::get('default_glue_mask'))->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setFocusName($nameClean . '_1'); }
/** * Constructor * * Create a new SelectList * * @param FormHandler $form The form where this field is located on * @param string $name The name of the field * @param array $options The options of the field * @return \FormHandler\Field\SelectList * @author Teye Heimans * @author Marien den Besten */ public function __construct(FormHandler $form, $name, $options = array()) { $this->field_values = new \FormHandler\Field\Hidden($form, $name); $this->field_values->setDefaultValue(array()); static $bSetJS = false; // needed javascript included yet ? if (!$bSetJS) { $bSetJS = true; $form->_setJS(\FormHandler\Configuration::get('fhtml_dir') . "js/listfield.js", true); } // make the fields of the SelectList $this->field_on = new \FormHandler\Field\Select($form, $name . '_ListOn'); $this->field_off = new \FormHandler\Field\Select($form, $name . '_ListOff'); $this->field_on->setMultiple(true); $this->field_off->setMultiple(true); return parent::__construct($form, $name)->setOptions($options)->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setSize(\FormHandler\Configuration::get('default_listfield_size'))->setOffTitle(\FormHandler\Language::get(29))->setOnTitle(\FormHandler\Language::get(30))->setFocusName($name . '_ListOn'); }
* 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;
* * 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\Button::set($form, 'Click me!', 'btn_1')->setConfirmation('Do you really want to click this button?'); $form->addLine('<br>Button with confirmation and description on click', true); Button\Button::set($form, 'Click me!', 'btn_2')->setConfirmation('Do you really want to click this button?')->setConfirmationDescription('And some extra description'); $form->addLine('<br>Button with confirmation, description and alert after confirmation approved', true); Button\Button::set($form, 'Click me!', 'btn_3')->setConfirmation('Do you really want to click this button?')->setConfirmationDescription('And some extra description')->setExtra('onclick="alert(\'This alert should be displayed after confirmation is success\');"'); //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 button confirmation<hr>'; echo $form_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 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)->setDefaultValue('Value ' . $i); } $form->link('field_1', 'field_2', function () { return FormHandler::returnDynamic(null, null, true, null, null); }); $form->getField('field_10')->setDisabled(); //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 disabling fields through links or directly at field level.<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 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('<br>Button with custom confirmation handler', true); Button\Button::set($form, 'Click me!', 'btn_4')->setConfirmation('Do you really want to click this button?')->setConfirmationDescription('And some extra description')->setExtra('onclick="alert(\'Custom handler successfully executed\')"'); $form->addHTML('<div id="testResult"></div>'); //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 custom button confirmation handler<hr> ' . $form_html . ' <script> $(document).ready(function() { var div = $("#testResult"), confirm = function(message, description, callable, options) { if(div.hasClass(\'active\'))
/** * Get the form * * @param boolean $return * @return string|null */ public function flush($return = false) { $form = parent::flush(); // return or print the form if ($return) { return $form; } else { echo $form; return null; } }
* 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;
* 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;
/** * Field::getViewMode() * * Return if this field is set to view mode * * @return bool * @author Teye Heimans */ public function getViewMode() { return $this->view_mode || $this->form_object->isViewMode(); }
/** * Constructor * * Create a new file field * * @param FormHandler $form The form where this field is located on * @param string $name The name of the field * @return \FormHandler\Field\File * @author Teye Heimans * @author Marien den Besten */ public function __construct(FormHandler $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/upload.js", true); } parent::__construct($form, $name); $form->setEncoding(FormHandler::ENCODING_MULTIPART); //upload fields are required by default $this->setRequired(true); $this->accept = array(); $this->drop_zone_enabled = false; $this->drop_zone_language = array('drop_file' => 'Drop your file here', 'too_large' => 'Given file is too large (Given: %given%, allowed: %allowed%)'); $this->async = !is_null(filter_input(INPUT_POST, $name . '_submit')); $this->button_upload = new Button($form, $name . '_button'); $this->button_upload->setCaption('Choose File')->setExtra('style="display:none;" class="upload"'); $this->button_edit = new \FormHandler\Button\Submit($form, $name . '_change'); $this->button_edit->setCaption('Change file')->setExtra('class="upload"')->onClick(function (FormHandler $form) use($name) { $form->setValidationDisabled(true); $form->setIsCorrect(false); $form->getField($name)->updateState(\FormHandler\Field\File::STATE_EMPTY, null, null); }); //read all open uploads $status = $this->readOpenUploads(); //by default generate a new token $generated_token = $this->generateToken(); //create field $this->token = new \FormHandler\Field\Hidden($form, $name . '_token'); $this->token->setDefaultValue($generated_token); $this->filename = new \FormHandler\Field\Hidden($form, $name . '_filename'); $this->filename->setDefaultValue(''); $this->state = new \FormHandler\Field\Hidden($form, $name . '_state'); $this->state->setDefaultValue(self::STATE_EMPTY); //process token $unsecure_token = $this->token->getValue(); $token = $this->form_object->isPosted() && !array_key_exists($unsecure_token, $status) ? $generated_token : $unsecure_token; $this->token->setValue($token); $data = $this->readState(); try { $result = $this->processUpload(); } catch (Exception $e) { $result = false; $data = $this->updateState($e->getCode(), null, null); } if ($result !== false && is_array($result)) { $data = $this->updateState(self::STATE_UPLOADED, $result[0], $result[1]); } if ($this->async) { $ajax = array('state' => $data['state'], 'name' => $data['last_processed']); //there was an javascript file submit, return state //do not send json header because IE will behave strange echo json_encode($ajax); exit; } //incorporate max file size if (!$form->fieldExists('MAX_FILE_SIZE')) { \FormHandler\Field\Hidden::set($form, 'MAX_FILE_SIZE')->setValue($this->getMaxUploadSize(), true)->hideFromOnCorrect(); } return $this; }