<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Select list with tip text
$objCat = $objForm->addField("cat", "Category", ValidForm::VFORM_SELECT_LIST, [], [], ["tip" => "Cool tip"]);
$objCat->addField("Red", 'R');
$objCat->addField("Green", 'G');
$objCat->addField("Blue", 'B');
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

/**
 * Hide field when other fields value is 'Robin'
 * Show that field if it's not Robin anymore
 */
use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Basic Condition and Comparison
$objFirstName = $objForm->addField('firstname', 'First name', ValidForm::VFORM_STRING);
$objLastName = $objForm->addField('lastname', 'Last name', ValidForm::VFORM_STRING);
$objLastName->addCondition('visible', false, array(new \ValidFormBuilder\Comparison($objFirstName, ValidForm::VFORM_COMPARISON_EQUAL, 'Robin')));
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Select element with start - end meta
$objForm->addField("rating", "Rate ValidForm Builder", ValidForm::VFORM_SELECT_LIST, array(), array(), array("start" => 1, "end" => 5));
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>ValidForm Sandbox</title>
    <!-- bower:css -->
    <!-- endbower -->
	<link rel="stylesheet" type="text/css" href="vendor/composer.css">

    <!-- bower:js -->
    <script src="vendor/jquery/dist/jquery.js"></script>
    <!-- endbower -->
	<script src="vendor/composer.js"></script>
</head>
<body>

<?php 
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Required checklist
/* @var $objCheck ValidFormBuilder\Group */
$objCheck = $objForm->addField("cool", "Awesome field", ValidForm::VFORM_CHECK_LIST, array("required" => true));
$objCheck->addField("Cool stuff", "coolio");
$objCheck->addField("Cool stuff2", "coolio2");
$objCheck->addField("Cool stuff3", "coolio3");
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
Ejemplo n.º 5
0
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Add a textarea
$objForm->addField("message", "Your Message", ValidForm::VFORM_TEXT, array("required" => true), array("required" => "This is a required field"), array("cols" => 20, "rows" => 10));
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Select element with label and value ranges
$objForm->addField("rating", "Rate ValidForm Builder", ValidForm::VFORM_SELECT_LIST, array(), array(), array("labelRange" => array("Awesome", "Great", "Super Cool", "Splendid", "Best thing ever happened"), "valueRange" => array(1, 2, 3, 4, 5)));
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
Ejemplo n.º 7
0
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Create a file upload field
$objForm->addField("logo", "Upload logo", ValidForm::VFORM_FILE, array(), array(), array("fieldclass" => "validform-logo"));
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Radio list with custom class on container
/* @var $objCat ValidFormBuilder\Group */
$objCat = $objForm->addField("cat", "Category", ValidForm::VFORM_RADIO_LIST, [], [], ["fieldclass" => "awesome-list"]);
$objCat->addField("Red", 'R');
$objCat->addField("Green", 'G');
$objCat->addField("Blue", 'B');
$objCat->addField("Orange", 'O');
$objCat->addField("White", 'W');
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

/**
 * Make field enabled when other field's value is 'yes'
 * Field will becom disabled when other field's value is 'no'
 * 
 * Note: enabled/disabled is NOT the same as visible/hidden!
 */
use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Basic yes/no condition
$objCheck = $objForm->addField("yesno", "Yes or No", ValidForm::VFORM_RADIO_LIST);
$objYes = $objCheck->addField("Yes", "yes");
$objCheck->addField("No", "no");
$objText = $objForm->addField("textfield", "Text here", ValidForm::VFORM_TEXT, array("required" => "true"), array("required" => "This field is required"), array("fielddisabled" => "disabled"));
$objText->addCondition("enabled", true, array(new Comparison($objYes, ValidForm::VFORM_COMPARISON_EQUAL, "yes")));
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
Ejemplo n.º 10
0
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Standard select element
$objSelect = $objForm->addField("rating", "Rate ValidForm Builder", ValidForm::VFORM_SELECT_LIST);
$objSelect->addField("Awesome", 1);
$objSelect->addField("Great", 2);
$objSelect->addField("Super Cool", 3, true);
// This item is selected by default
$objSelect->addField("Splendid", 4);
$objSelect->addField("Best thing ever happened", 5);
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Basic string input field
$objForm->addField("name", "Enter your name", ValidForm::VFORM_STRING, [], ["type" => "Invalid characters"]);
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

/**
 * Demonstration of the meta key 'default'
 */
use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Check list with multiple default values
/* @var $objCat ValidFormBuilder\Group */
$objCat = $objForm->addField("cat", "Category", ValidForm::VFORM_CHECK_LIST, [], [], ["default" => ["R", "G"]]);
$objCat->addField("Red", 'R');
$objCat->addField("Green", 'G');
$objCat->addField("Blue", 'B');
$objCat->addField("Orange", 'O');
$objCat->addField("White", 'W');
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Add fieldset
$objFieldset = $objForm->addFieldset("Cool fieldset label");
/**
 * Now, instead of doing this:
 * $objFieldset->addField( .... )
 * You can just do this:
 */
$objForm->addField("hello", "Cool field in fieldset", ValidForm::VFORM_STRING);
/**
 * ValidForm Builder automatically searches for the last created Fieldset and appends the newly created field to it.
 * See issue #15 for more details
 */
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}
<?php

use ValidFormBuilder\ValidForm;
require '../vendor/autoload.php';
$objForm = new ValidForm("test");
//*** Match two password fields
$objNewPassword = $objForm->addField("new-password", "New Password", ValidForm::VFORM_PASSWORD);
$objForm->addField("repeat-password", "Repeat Password", ValidForm::VFORM_PASSWORD, array("matchWith" => $objNewPassword), array("matchWith" => "Password fields do not match"));
//*** Generate form output
if ($objForm->isValid() && $objForm->isSubmitted()) {
    $strCheckboxValue = $objForm->getValidField("rating")->getValue();
    $strOutput = $objForm->valuesAsHtml();
} else {
    $strOutput = $objForm->toHtml();
}