\Vigas\Application\ControllerFormBuilder

Class FormBuilder.

Builds HTML form

Summary

Methods
Properties
Constants
__construct()
__toString()
addInputHTML()
addTextareaHTML()
addSelectHTML()
addCheckboxHTML()
addMultipleCheckboxHTML()
addOneCheckboxHTML()
addRadioHTML()
addCaptcha()
addSubmitButton()
addTextHTML()
No public properties found
No constants found
No protected methods found
$html_fields
$target_url
$method
$class
N/A
surroundWithLabel()
surround()
No private properties found
N/A

Properties

$html_fields

$html_fields : string

Type

string — Contains all the form HTML fields

$target_url

$target_url : string

Type

string — Page's URL that handles the form data

$method

$method : string

Type

string — The HTTP method to be used when submitting the form (GET or POST)

$class

$class : string

Type

string — The HTML class attribute name

Methods

__construct()

__construct(string  $target_url, string  $method, string  $class = null) 

Sets attributes $target_url, $method and $class if not null

Parameters

string $target_url

Page's URL that handles the form data

string $method

The HTTP method to be used when submitting the form (GET or POST)

string $class

The HTML class attribute name

__toString()

__toString() : string

Defines how the FormBuilder object will be displayed when called by echo

Returns

string —

The form to display

addInputHTML()

addInputHTML(string  $id, string  $label, string  $type, string  $name, string  $value = '', string  $attribute = '') 

Adds an input field to the html_fields attribute

Parameters

string $id

The input id attribute

string $label

The element label

string $type

The input type attribute

string $name

The input name attribute

string $value

The input default value

string $attribute

Any other HTML attribute

addTextareaHTML()

addTextareaHTML(string  $id, string  $label, string  $type, string  $name, string  $rows, string  $value = '', string  $attribute = '') 

Adds a textarea field to the html_fields attribute

Parameters

string $id

The textarea id attribute

string $label

The element label

string $type

The textarea type attribute

string $name

The textarea name attribute

string $rows

The textarea rows number

string $value

The textarea default value

string $attribute

Any other HTML attribute

addSelectHTML()

addSelectHTML(string  $id, string  $label, string  $name, array  $options, string  $selected = '') 

Adds a select field to the html_fields attribute

Parameters

string $id

The element id attribute

string $label

The element label

string $name

The element name attribute

array $options

List of options

string $selected

The default selected option

addCheckboxHTML()

addCheckboxHTML(string  $id, string  $label, string  $type, string  $name, string  $class, string  $attribute = '') : string

Creates an HTML checkbox field

Parameters

string $id

The checkbox id attribute

string $label

The checkbox label

string $type

The checkbox type attribute

string $name

The checkbox name attribute

string $class

The HTML class attribute

string $attribute

Any other HTML attribute

Returns

string —

An HTML checkbox field

addMultipleCheckboxHTML()

addMultipleCheckboxHTML(string  $checkbox_array, string  $main_label) 

Adds multiple checkbox fields to the html_fields attribute

Parameters

string $checkbox_array

Contains all the checkboxes

string $main_label

The element label

addOneCheckboxHTML()

addOneCheckboxHTML(string  $id, string  $label, string  $type, string  $name, string  $class, string  $attribute = '', string  $main_label = '') 

Adds a checkbox field to the html_fields attribute

Parameters

string $id

The checkbox id attribute

string $label

The checkbox label

string $type

The checkbox type attribute

string $name

The checkbox name attribute

string $class

The HTML class attribute

string $attribute

Any other HTML attribute

string $main_label

The main element label

addRadioHTML()

addRadioHTML(string  $id, string  $main_label, string  $type, array  $radios, string  $class, string  $attribute = '') 

Adds radios fields to the html_fields attribute

Parameters

string $id

The radio id attribute

string $main_label

The radio main label

string $type

The radio type attribute

array $radios

All radios name and label attribute

string $class

The HTML class attribute

string $attribute

Any other HTML attribute

addCaptcha()

addCaptcha() 

Adds a Google captcha field to the html_fields attribute

addSubmitButton()

addSubmitButton(string  $label, string  $name, string  $class) 

Adds a submit button to the html_fields attribute

Parameters

string $label

The submit button label

string $name

The submit button name attribute

string $class

The HTML class attribute

addTextHTML()

addTextHTML(string  $text) 

Adds a text to the html_fields attribute

Parameters

string $text

The text to add

surroundWithLabel()

surroundWithLabel(string  $element, string  $label = '') 

Surrounds a form field with label attribute and a div

Parameters

string $element

The form element

string $label

The element label

surround()

surround(string  $element) 

Surrounds a form field with a div

Parameters

string $element

The form element