Class: Zebra_Form_Label
source file: /includes/Label.php
Class Overview
XSS_Clean
|
--Zebra_Form_Control
|
--Zebra_Form_Label
Class for labels
Author(s):
Copyright:
- (c) 2006 - 2013 Stefan Gabos
Class methods
constructor __construct()
void
__construct (
string
$id
,
string
$attach_to
,
mixed
$caption
,
[
array
$attributes
= '']
)
Add an <label> control to the form.
Do not instantiate this class directly! Use the add() method instead! // create a new form
// add a label, attached to a textbox control
$form->add('label', 'label_my_text', 'my_text', 'Enter some text:');
// add a text control to the form
$obj = $form->add('text', 'my_text');
// don't forget to always call this method before rendering the form
if ($form->validate()) {
// put code here
}
// output the form using an automatically generated template
$form->render();
Parameters:
| string |
$id |
Unique name to identify the control in the form. This is the name of the variable to be used in the template file, containing the generated HTML for the control. // in a template file, in order to print the generated HTML
// for a control named "my_label", one would use:
echo $my_label;
|
| string |
$attach_to |
The id attribute of the control to attach the note to. Notice that this must be the "id" attribute of the control you are attaching
the label to, and not the "name" attribute! This is important as while most of the controls have their id attribute set to the same value as their name attribute, for checkboxes, selects and radio buttons this is different. Exception to the rule: Just like in the case of notes, if you want a master label, a label that is attached to a group of checkboxes/radio buttons rather than individual controls, this attribute must instead refer to the name of the controls (which, for groups of checkboxes/radio buttons, is one and the same). This is important because if the group of checkboxes/radio buttons have the required rule set, this is the only way in which the "required" symbol (the red asterisk) will be attached to the master label instead of being attached to the first checkbox/radio button from the group. |
| mixed |
$caption |
Caption of the label. Putting a $ (dollar) sign before a character will turn that specific character into
the accesskey. If you need the dollar sign in the label, escape it with \ (backslash) |
| array |
$attributes |
(Optional) An array of attributes valid for label elements (style, etc) Must be specified as an associative array, in the form of attribute => value. // setting the "style" attribute
$obj = $form->add(
'label',
'label_my_text',
'my_text',
'My Label:'
array(
'style' => 'font-weight: normal'
)
);
Special attribute: When setting the special attribute inside to true, the label will appear inside the control is attached to (if the control the label is attached to is a textbox or a textarea) and will disappear when the control will receive focus. When the "inside" attribute is set to TRUE, the label will not be available in the template file as it will be contained by the control the label is attached to! $form->add('label', 'my_label', 'my_control', 'My Label:', array('inside' => true));
Sometimes, when using floats, the inside-labels will not be correctly positioned
as jQuery will return invalid numbers for the parent element's position; If this is
the case, make sure you enclose the form in a div with position:relative to fix
this issue. See set_attributes() on how to set attributes, other than through the constructor. The following attributes are automatically set when the control is created and should not be altered manually: id, for |
Top
method toHTML()
string
toHTML (
)
Generates the control's HTML code.
This method is automatically called by the render() method!
Tags:
| return: |
The control's HTML code |
Top
|