VFORM_STRING
VFORM_STRING = 1 : \ValidFormBuilder\number
Input type[text] with standard string validation
ValidWizard class - Create multiple pages with formfields and next - previous buttons
Note: Make sure you also include validwizard.js
when using ValidWizard. This javascript library is not
required when you're not using ValidWizard.
// The signature is exactly the same as with ValidForm
$objForm = new ValidWizard(
"awesome-wizard",
"Please fill out my cool wizard",
"/stuff",
array(
// When no 'nextLabel' meta is set, defaults to 'Next →'
"nextLabel" => "Move on →",
// When no 'previousLabel' meta is set, defaults to '← Previous'
"previousLabel" => "Retreat!"
)
);
$objForm->addPage(
"personal-details",
"Personal Details"
);
__construct(string $name, string $description = null, string|null $action = null, array $meta = array())
Create an instance of the ValidForm Builder
string | $name | The name and id of the form in the HTML DOM and JavaScript. |
string | $description | Desriptive text which is displayed above the form. Default |
string|null | $action | Form action. If left empty the form will post to itself. Default |
array | $meta | The meta array |
setDefaults(array $arrDefaults = array())
Use an array to set default values on all the forms children.
The array's keys should be the form name to set the default value of, the value is the actual value or values to set.
Example 1 - Basic defaults:
//*** The form
$objCheck = $objForm->addField("cool", "Coolest PHP Library", ValidForm::VFORM_STRING);
//*** Set field 'cool' default value to "ValidForm Builder"
$objForm->setDefaults([
"cool" => "ValidForm Builder"
]);
Example 2 - An array of defaults:
//*** The form
$objCheck = $objForm->addField("cool", "Cool checklist", ValidForm::VFORM_CHECK_LIST);
$objCheck->addField("Option 1", "option1");
$objCheck->addField("Option 2", "option2");
$objCheck->addField("Option 3", "option3");
$objCheck = $objForm->addField("cool-text", "Coolest PHP Library", ValidForm::VFORM_STRING);
//*** Check options 2 and 3 by default using setDefaults()
$objForm->setDefaults([
"cool-text" => "ValidForm Builder",
"cool" => ["option2", "option3"]
]);
array | $arrDefaults | The array of default values. Keys are field names, values strings or arrays |
addHtml(string $html, array $meta = array()) : \ValidFormBuilder\StaticText
Injects a string in the form.
Use this to add an extra string in the form. For instance, you can create an input field like this:
Enter the amount: $ _____
In this example, we used StaticText to inject the dollar sign before our input field.
string | $html | The string or HTML code to inject |
array | $meta |
addNavigation(array $meta = array()) : \ValidFormBuilder\Navigation
Add 'navigation' to the form. By navigation we mean a 'navigation div' at the buttom of the form containing the submit button. This method is optional for customization purposes -- navigation is created automatically.
array | $meta | Array with meta data. Only the "style" attribute is supported as for now. |
addFieldset(string $header = null, string $noteHeader = null, string $noteBody = null, array $meta = array()) : \ValidFormBuilder\Fieldset
Add a fieldset
See \ValidFormBuilder\ValidForm::addFieldset()
string | $header | The header for this fieldset |
string | $noteHeader | An optional header for the 'note' block on the side of this fieldset |
string | $noteBody | The optional body for the 'note block on the side of this fieldset |
array | $meta | The meta array |
addHiddenField(string $name, string $type, array $meta = array(), boolean $blnJustRender = false) : \ValidFormBuilder\Hidden
Add a hidden input field to the form collection.
Hidden fields can be used for example to inject custom values in your post data and still have them validated using ValidForm Builder.
string | $name | The hidden field's |
string | $type | Define a validation type using one of the |
array | $meta | Optional meta array |
boolean | $blnJustRender | If true, only create a {@link \ValidFormBuilder\Hidden} instance and return it.
When false, this {@link \ValidFormBuilder\Hidden} instance is added to the internal |
renderField(string $name, string $label, integer $type, array $validationRules, array $errorHandlers, array $meta) : \ValidFormBuilder\Element
Use this utility method to only render \ValidFormBuilder\Element instances of the defined types.
Elements rendered with this method aren't added to the internal elements collection.
string | $name | The element's name |
string | $label | The element's label |
integer | $type | The element's validation type |
array | $validationRules | Optional.Custom validation rules array |
array | $errorHandlers | Custom error handling array |
array | $meta | Optional. Meta data array |
Returns null when no valid type is defined
addField(string $name, string $label, integer $type, array $validationRules = array(), array $errorHandlers = array(), array $meta = array(), boolean $blnJustRender = false) : \ValidFormBuilder\Element
Add a field
See \ValidFormBuilder\ValidForm::addField()
string | $name | The element's name |
string | $label | The element's label |
integer | $type | The element's validation type |
array | $validationRules | Optional.Custom validation rules array |
array | $errorHandlers | Custom error handling array |
array | $meta | Optional. Meta data array |
boolean | $blnJustRender | When true, the element is not added to the internal elements collection.
|
Returns null when no valid type is defined
addParagraph(string $strBody, string $strHeader = "", array $meta = array()) : \ValidFormBuilder\Paragraph
Adds a \ValidFormBuilder\Paragraph object to the internal elements collection.
This renders a paragraph inside the form. Formfields can be added before and after the paragraph. Example:
$objForm->addField("name", "Your Name", ValidForm::VFORM_STRING);
$objForm->addParagraph("Next, you should enter your last name.", "Enter your name!");
$objForm->addField("last-name", "Last Name", ValidForm::VFORM_STRING);
string | $strBody | Paragraph body |
string | $strHeader | Optional header above the paragraph |
array | $meta | Custom meta array |
addButton(string $strLabel, array $arrMeta = array()) : \ValidFormBuilder\Button
Adds a <button> element to the internal fields collection.
For an example; see \ValidFormBuilder\Button
string | $strLabel | The button's label |
array | $arrMeta | The meta array |
addArea(string $label = null, boolean $active = false, string $name = null, boolean $checked = false, array $meta = array()) : \ValidFormBuilder\Area
Add an area to the internal elements collection.
See \ValidFormBuilder\Area for examples
string | $label | The title of this area |
boolean | $active | If |
string | $name | The ID of this area |
boolean | $checked | Use in combination with |
array | $meta | The meta array |
addMultiField(string $label = null, array $meta = array()) : \ValidFormBuilder\MultiField
Add multifield
See \ValidFormBuilder\ValidForm::addMultiField()
string | $label | |
array | $meta | The meta array |
addJSEvent(string $strEvent, string $strMethod)
Add a custom javascript event with corresponding callback function
With this method you can either register a custom callback function on one of the predefined custom events or you can register the callback function on a jQuery bindable event (e.g. jQuery().bind(eventName, callback)).
These are predefined event hooks in the ValidForm Builder client-side library:
string | $strEvent | The event name |
string | $strMethod | The name of the callback function |
toHtml(boolean $blnClientSide = true, boolean $blnForceSubmitted = null, string $strCustomJs = "") : string
Generate HTML output - build form
boolean | $blnClientSide | Render javascript code or not, defaults to true |
boolean | $blnForceSubmitted | This forces the form rendering as if the fields are submitted |
string | $strCustomJs | Inject custom javascript to be executed while initializing ValidForm Builder client-side. |
Generated HTML output
fieldsToHtml(boolean $blnForceSubmitted = false, boolean $blnNavigation = false) : string
This method generates HTML output for the current internal elements collection.
This method is mostly used internally in the library and it's therefore not recommended to use this except for these rare occasions when you only want the rendered fields an not all the meta surrounding the fields like the form tag, description element and form error message.
boolean | $blnForceSubmitted | This forces the form rendering as if the fields are submitted |
boolean | $blnNavigation | This is a reference returning true if the form contains a navigation element |
Generated HTML output
toJs(string $strCustomJs = "") : string
Generate the Javascript output only.
This is particulary useful when using ValidForm Builder in combination with AJAX form handling. In that case you don't want to output the HTML together with the javascript.
string | $strCustomJs | Inject custom javascript to be executed while initializing ValidForm Builder client-side. |
elementsToJs(boolean $blnRawJs = false) : string
Generate the Javascript output only for the fields and conditions.
This is particulary useful when using ValidForm Builder in combination with AJAX form handling. You can inject new fields and field logic into an existing ValidForm and all validation will be handled by that "parent" form.
boolean | $blnRawJs | Return javascript without the surrounding |