SD_Forms is a XHTML form class that handles: creation, display and validation of form elements and complete form layouts. More...
Public Member Functions | |
| __construct ($options=array()) | |
| make_id ($options) | |
| start () | |
| stop () | |
| make_label ($options) | |
| make_description ($options) | |
| make_input ($options) | |
| add_section ($section) | |
| use_post_value (&$input, $post_data=null) | |
| add_section_input ($section, $input, $settings, $post_data=null) | |
| add_text_section ($sectionName, $text) | |
| add_layout ($layouts, $inputData, $settings, $postData=null) | |
| display () | |
| validate_post ($inputs, $inputs_to_check, $values) | |
| l ($string, $replacementString=array()) | |
Static Public Member Functions | |
| static | get_post_data ($callingClass, $POST=null) |
| static | fix_name ($name) |
| static | make_name ($options) |
| static | generate_changed_sql ($inputs, $inputsToChange, $tableName, $uniqueKey, $oldValues, $newValues) |
| static | valid_email ($email) |
Protected Attributes | |
| $language_data = array() | |
Private Member Functions | |
| make_required_field ($options) | |
| make_validation ($options) | |
| implode_array ($data, &$strings, $glueBefore, $glueAfter, $stringPrefix=null, $currentString=null) | |
Private Attributes | |
| $options | |
| $default_options | |
| $sections = array() | |
SD_Forms is a XHTML form class that handles: creation, display and validation of form elements and complete form layouts.
Form handling class
-------------------
First, create the class:
$form = new SD_Forms();
During your display of the HTML:
echo $form->start();
Now you can build your forms using arrays as inputs.
$input_text = array( 'name' => 'my_text_example', 'type' => 'text', 'size' => 60, // recommended that you have any size specified 'css_class' => 'text_area_orange', // optional 'css_style' => 'font-size: 500%;', // optional 'value' => 'This is the default text displayed', // optional 'description' => 'This is a short, optional description. Note that you'll need to put divs around the description in order to do interesting stuff with it.', );
echo $form->make_label( $input_text ); // The accessible label echo $form->make_input( $input_text ); // The input itself echo $form->make_description( $input_text ); // displays only the description, including validation info.
And to finish up the form after displaying:
echo $form->stop();
Most of the input types have the css_class, css_style, description, value fields in common. checkbox
$input_checkbox = array( 'name' => 'checkbox_example', 'type' => 'checkbox', 'label' => 'Label of checkbox', 'checked' => true, );
value, description is optional.
file
$input_file = array( 'name' => 'file_example', 'type' => 'file', 'value' => 'Text on button', );
image
An image is used instead of a submit button.
$input_image = array( 'name' => 'image_example', 'type' => 'image', 'label' => 'ALT value of image' 'src' => 'images/submit.png', );
password
Similar to text, except that the value isn't displayed.
$input_password = array( 'name' => 'password_example', 'type' => 'password', 'label' => 'Displayed label', );
radio
$input_radio = array(
'name' => 'radio_example',
'type' => 'radio
'label' => 'Label of radio box',
'options' => array(
'option001' => 'First radio option',
'option002' => 'Second radio option',
),
);
select
$input_select = array(
'name' => 'select_example',
'type' => 'select',
'label' => 'Label of select',
'multiple' => false, // Allow selection of multiple values
'size' => 5, // How many option rows to display.
'options' => array(
'option001' => 'First select option',
'option002' => 'Second select option',
),
);
submit
$input_submit = array( 'name' => 'submit_example', 'type' => 'submit', 'value' => 'Displayed on the button', );
text
$input_text = array( 'name' => 'text_example', 'type' => 'text 'label' => 'Label of text box', );
textarea
$input_textarea = array( 'name' => 'textarea_example', 'type' => 'textarea', 'label' => 'Label of text area', 'rows' => 80, 'cols' => 10, );
To add validation to your input, add a key called validation and make it an array with any of the following keys:
empty Field is allowed to be empty
valuemin Integer value: minimum
valuemax Integer value: maximum
datetime Date must be in this format. (Use format keywords from date(). "Y-m-d").
datemaximum Latest date/time allowed. Any date() format.
lengthmin Length: minimum
Validation example:
$input_text = array( 'name' => 'text_example', 'type' => 'text 'label' => 'Label of text box', 'validation' => array( 'empty' => true, ), );
| SD_Form::__construct | ( | $options = array() | ) |
| SD_Form::add_layout | ( | $layouts, | |
| $inputData, | |||
| $settings, | |||
$postData = null |
|||
| ) |
Adds sections + inputs "automatically".
Using $layout, the modules $settings module and the postdata, it creates a form with section and inputs.
Example layout
private $inputLayout = array( 0 => array( 'name' => 'ExampleSection', 'description' => 'This section deals with examples. Examples are good.', 'autoinputs' => array( 'IFACMS_STAGE_PAGE_TITLE_SEPARATOR' => array('text'), ), // Inputs 'inputs' => array( array( 'type' => 'submit', 'name'=>'CHANGE_SETTINGS_BASE', 'value' => 'Change settings', ) ), // Manualinputs ), // 0 ); // inputLayout
Tip: If your module requires several pages/tabs of settings, put the layouts in one big layoutarray and make the tab name the key.
| SD_Form::add_section | ( | $section | ) |
Adds a section.
$section = array( 'name' => 'Name of the section', 'description' => 'Section description that tells the user what this section is about.', 'inputs' => RESERVED )
| SD_Form::add_section_input | ( | $section, | |
| $input, | |||
| $settings, | |||
$post_data = null |
|||
| ) |
Adds an input to a section. Kinda like makeInput, but with a section name.
| SD_Form::add_text_section | ( | $sectionName, | |
| $text | |||
| ) |
| SD_Form::display | ( | ) |
Displays a whole form with sections and all the section inputs.
|
static |
Cleans up the name of an input, remove illegal characters.
|
static |
Generates an SQL-statement that either updates or inserts the values into a table.
On an update, it only changes the values that have changed (compares newvalues to oldvalues).
| $inputs | array An array of inputs in standard input format (see top). |
| $inputsToChange | array An array of names of which inputs to change. |
| $tableName | string The table's name. |
| $uniqueKey | string The unique key column name. |
| $oldValues | array Associative array of old values. |
| $newValues | array Associative array of new values. |
|
static |
Returns the _POST data of the calling class.
|
private |
| SD_Form::l | ( | $string, | |
$replacementString = array() |
|||
| ) |
Returns the translated string, if any.
| SD_Form::make_description | ( | $options | ) |
Returns the description of this input.
| SD_Form::make_id | ( | $options | ) |
Returns a text ID of this input.
| SD_Form::make_input | ( | $options | ) |
Makes an input string.
| SD_Form::make_label | ( | $options | ) |
Returns the label of this input.
|
static |
Returns the name of this input.
|
private |
Makes a small asterisk thingy that is supposed to symbolise that the field is required.
|
private |
| SD_Form::start | ( | ) |
Returns a simple <form> tag (with action and method set).
| SD_Form::stop | ( | ) |
Returns </form>. That's it.
| SD_Form::use_post_value | ( | & | $input, |
$post_data = null |
|||
| ) |
|
static |
Validate an email address.
| $email Email address to validate |
| SD_Form::validate_post | ( | $inputs, | |
| $inputs_to_check, | |||
| $values | |||
| ) |
Validates the values based on $inputs and which of the $inputs to check.
Returns an array of $key / 'error message' if validation fails, else returns true.
|
private |
|
protected |
|
private |
|
private |
1.8.1.2