scbForms Reference
scbForms is a class that simplifies form generation.
input($args, $formdata = array())
This is the main method, with which you can generate one or more form elements of the same type, including <select>s and <textarea>s.
$args is an associative array of arguments that define what form element should be generated.
General args:
- type – string (mandatory)
- name – string | array (mandatory)
- value – string | array
- desc – string | array | bool
- desc_pos – ‘before’ | ‘after’ | ‘foo %input% bar’ (default: after)
- extra – string | array Extra HTML attributes like class, style etc.
‘checkbox’ and ‘radio’ specific arguments:
- checked => bool | string Force the radio button to be checked or not
‘select’ specific arguments:
- text – bool | string By default, an empty option is generated. This can be disabled by setting the text argument to false
- selected – string Force a certain option to be selected
- numeric – bool (default: false) If set to false, the method will attempt to convert a numeric array to an associative one
$formdata is also an associative array with the formdata with which to pre-fill the elements.
Examples
Simple text input:
scbForms::input(array( 'type' => 'text', 'name' => 'title', 'value' => 'Insert title here', ));
The input will be prefilled with the text ‘Insert title here’.
Multiple radio buttons:
$data = array( 'size' => 'medium' ); scbForms::input(array( 'type' => 'radio', 'name' => 'size', 'values' => array('small', 'medium', 'large') ), $data);
This will generate three radio buttons, with the middle one selected.
A dropdown element:
$data = array( 'language' => 'en' ); scbForms::input(array( 'type' => 'select', 'name' => 'language', 'values' => array( 'en' => 'English', 'fr' => 'French', 'de' => 'German' ) ), $data);
This will generate a <select> element with 3 options. The selected one will be ‘en’.
