* 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
Example #2
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>';
Example #3
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;
 public static function set(\FormHandler\FormHandler $form, $title, $name, $validator = null)
 {
     $field = parent::set($form, $title, $name);
     return $field->setValidator(FormHandler::parseValidator($validator, $field))->useArrayKeyAsValue(false);
 }
 * 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;
 * 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;
 /**
  * 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);
 }
 * 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;
Example #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 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;
Example #10
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;
 * 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;