Form helper

Helper methods to simply form creation and automatically meet XHTML and accessibility standards. To simplify form validation, all form elements automatically maintain their values when the form is submitted to the same page.

open(array $args = array())

Opens the form container. This method will not let you open a second form if one is already open; if you try while debug mode is enabled this will throw a PHP user notice.
All $args are optional and turn into properties of the HTML form tag, a few are handled specially:

action - where the form gets submitted to, if omitted the current REQUEST_URI is used.

method - either get or post (default is post)

title - if you set the title it is used for both title and form legend

legend - if you set legend and omit title, then legend is used as the title too

alert - displays a message at the top of the form wrapped in the errormessage CSS class

close()

Closes the form container. This method will not let you close a form if one is not open; if you try while debug mode is enabled this will throw a PHP user notice.

label - property available to all form elements

Adds a label tag to the input; if omitted it will generate a label based on the element name.
Two optional properties are available to control label display:

addBreak - Boolean, default is true - if true a BR tag is added between the label and the form element.

labelFirst - Boolean - determines if the label should preceed or follow the form element, the default is true for most elements, false for radio and checkboxes.

$_POST['errors']

Set a key to the name of any form element and the value will be displayed next to it with the errormessage CSS class applied, eg.:if (!isset($_POST['fullname'])) {$_POST['errors']['fullname'] = 'Fullname is required';
}
echo $html->input(array('name' => 'fullname'));
This will display the "Fullname is required" message in red above the fullname input if the fullname is omitted. (Note that this is only a sample for illustrative purposes and not the proper way to do form validation.)

input(array $args)

Valid $args keys are any properties that are valid within the HTML input. Options for $args['type'] must correspond to:

text (default, this is used if type is omitted)

hidden

password

file

button

image

submit

textarea

select - alias for the select() method

checkbox - alias for the checkboxes() method

radio - alias for the radios() method

Any input can specify the focus property which will cause the input to be in focus (the cursor will be in the box) upon page load.
Setting the maxlength property works with any element including textareas.
Textareas used for inputting HTML can utilize the Boolean preview property. When set to true a live-preview box appears under the textarea and shows a rendered display of the HTML that is entered into the textarea as it gets typed.
Textareas have an extra property of wysiwyg, which can be set to Boolean true or an array of options and the textarea will be displayed as a WYSIWYG textarea (requires the TinyMCE package to be installed.) Options can be any setting within the TinyMCE API.
Sample usage:echo $form->input(array('name' => 'email'));echo $form->input(array('type' => 'password', 'name' => 'password', 'label' => 'Confirm your password'));echo $form->input(array('type' => 'textarea', 'name' => 'content', 'wysiwyg' => true));echo $form->input(array('type' => 'hidden', 'name' => 'id', 'value' => '123456789'));echo $form->input(array('name' => 'submit'));

validatedInput(array $args)

Returns an input that is initialized to be validated using the Validator package. $args are the same as input().

radios(array $args)

Returns a set of radio inputs. Operates like input() except adds:

options - the array of radio options, can be either an associative array or dynamically-assigned numeric (but cannot mix the two)

optionBreak - set the text or HTML to appear between each option, default is the BR tag (for full display control use the $radios and $checkboxes array properties instead of echoing out the response of radios())

addFieldset - unless this is set to false, a fieldset will automatically wrap radio arrays consisting of two or more radio elements

checkboxes(array $args)

Works the same as radios() except allows value to be either a string or an array (to have multiple checkboxes checked by default.) Also, if you have 2 or more checkboxes in your options and your checkbox name is not in array form the PHP array brackets will be added for you.

$radios and $checkboxes array properties

These contain an array of the form radio or checkbox elements created in the last instance of radios() or checkboxes(). These properties allow fine-grained display control over your checkbox and radio elements. Sample usage:$html->radios($args);
echo implode(' -- ', $html->radios);

$months property

Contains an array mapping month numbers to human-friendly numer-name captions. This array is ideal to use as options for a credit card expiration month select box.

dateSelect(array $args)

Returns an array of selection boxes to select the date and/or time. Keys for $args are:

time - boolean, if true time selection will also be added - will be set true automatically if you set any options for the hour, minute or mil (below)