Class: SForm_Element
Source Location: /SForm.php
Class SForm_Element
Class Overview
|
A element is a "leaf" that is actually rendered
All elements and containers are decendents of this class. That said, this class is intended to cover as much common functionality as possible.
Located in /SForm.php [line 166]
Author(s):
API Tags:
|
Properties
|
Methods
|
Property Summary
| static integer |
$defId |
Number the elements if not given an ID |
| boolean |
$addName |
Should we add the 'name' attribute? |
| boolean |
$emptyTag |
Is this element's tag empty? |
| array |
$errors |
What were the results of the validation? |
| array |
$filters |
A list of filter callbacks |
| boolean |
$locked |
Are the rules & filters prevented from being modified? |
| object |
$parent |
What is the parent to this element? |
| boolean |
$required |
Is this a required element? |
| array |
$rules |
Rules to apply to this element |
| string |
$tag |
This is the element's tag ('input', 'select', 'form', etc) and should be set by the children as needed. |
| boolean |
$validated |
Has this element been validated? |
| boolean |
$valueSet |
Has the value for this element been set? |
Method Summary
| static
string
|
escHtml() |
Escape HTML in a consistant manner |
| static
string
|
getOption() |
Get a global option |
| SForm_Element |
__construct() |
Construct with an identity. Optionally add a label and more attributes. |
| object The |
addRule() |
Add a rule to this element |
| mixed |
autoAK() |
Generates an access key and updated label |
| object Created |
createRule() |
Creates & returns a rule |
| void |
filter() |
Apply a filter to the value |
| void |
freeze() |
Set if this element is frozen |
| string |
getLabel() |
Return the label string (no markup) |
| mixed |
getRequest() |
Returns a value from the request |
| mixed |
getValue() |
The value of this element |
| boolean |
isFrozen() |
Is this element marked as frozen? |
| void |
lock() |
Locks & adds any last minute stuff |
| void |
render() |
Append this leaf element to the render queue |
| void |
setDefault() |
Set the default value of this element |
| void |
setValue() |
Set the value of this element |
| string |
toHidden() |
Do we have any hidden tags to append? |
| string |
toHtml() |
Create a HTML representation of this element |
| string |
toJavaScript() |
Retrieve any JavaScript that should be run onsubmit |
| string |
toString() |
How does this value look as a HTML string? |
| boolean |
validate() |
Is this a valid element? |
Properties
Number the elements if not given an ID
API Tags:
Should we add the 'name' attribute?
API Tags:
Redefined in descendants as:
Attributes for this tag
API Tags:
Is this element's tag empty?
A tag is empty if it can't contain elements. Examples of empty tags include '<input />' and '<img />'. Non-empty tags include '<form>' and '<fieldset>'. API Tags:
Redefined in descendants as:
What were the results of the validation?
All error strings returned by validation are saved here. If there is no error string, then there was no error. API Tags:
A list of filter callbacks
API Tags:
Are the rules & filters prevented from being modified?
When the rules are rendered (or otherwise used), they are locked to prevent someone from adding an additonal rule. This would invalidate any calculations done using the previous ruleset. API Tags:
What is the parent to this element?
This points to some subclass of SForm_Container. It is set in SForm_Container::addElement(). API Tags:
Is this a required element?
If an element is marked as required, the 'required' rule is added at render time and modifications can be made to the label HTML which mark this element as required. API Tags:
Rules to apply to this element
API Tags:
This is the element's tag ('input', 'select', 'form', etc) and should be set by the children as needed.
API Tags:
Redefined in descendants as:
Has this element been validated?
Validated elements have a finished $errors array and will not be validated again. API Tags:
Has the value for this element been set?
API Tags:
Methods
static string escHtml(
string
$str
)
|
|
Escape HTML in a consistant manner
Parameters:
|
string |
$str: |
Text to escape |
API Tags:
| Return: | Text HTML escaped |
| Access: | public |
static string getAttributesString(
array
$attributes
)
|
|
Creates an HTML attribute string from an array
Parameters:
|
array |
$attributes: |
Attributes as: attribute => value |
API Tags:
| Return: | HTML string |
| Access: | protected |
static string getOption(
string
$name
)
|
|
Get a global option
All available options are pre-set in the $options array, so we will be avoiding some frusteration if we throw an error on a bad option selection. Otherwise, we could think that we are retrieving a null value, but we have just misspelled the index.
Parameters:
|
string |
$name: |
Option name |
API Tags:
| Return: | Option value |
| Access: | public |
| Uses: | $options |
static void setOption(
string
$name, string
$value
)
|
|
Set a global option
All available options are pre-set in the $options array, so we will be avoiding some frusteration if we throw an error on a bad option selection. Otherwise, we could think that we are retrieving a null value, but we have just misspelled the index.
Parameters:
|
string |
$name: |
Option name |
|
string |
$value: |
Option value |
API Tags:
| Access: | public |
| Uses: | $options |
SForm_Element __construct(
[string
$id = null], [string
$label = null], [array
$attributes = null]
)
|
|
Construct with an identity. Optionally add a label and more attributes.
$id is the Local ID of this element, and is similar to its name. If none is supplied, one will be created. The Local ID is different than the 'id' attribute that appears in the rendered form. The id attribute is referred to as the Global ID, and is the concatenation of the parent's Global ID, a colon, and this Local ID. The ID must contain only chars acceptable in the ID SGML token for the resulting page to be valid. The $label is the the short string that describes this element. If it is rendered as HTML, it will automatically be enclosed in '<label>' tags which referr to the Global ID of this element. If enabled, an appropriate access key will also be found for this element. The access key will be rendered with '<span class="ak">' and '</span>' tags surrounding it. If you wish to communicate with your users that this access key may be used to access this field, I suggest that you use CSS like: '.ak{text- decoration:underline;}'. Any additonal $attributes may be added and will be displayed when the element is rendered as HTML.
Parameters:
|
string |
$id: |
Local ID of this element |
|
string |
$label: |
Textual label for this element |
|
array |
$attributes: |
Array of extra attributes |
API Tags:
Information Tags:
Redefined in descendants as:
object The addRule(
mixed
$rule, [
$message = null], [
$arg2 = null], [
$arg3 = null], [
$arg4 = null], [
$arg5 = null], [
$arg6 = null]
)
|
|
Add a rule to this element
A rule assigned to this element will be controled by this element. All validation will come through this element, and any errors will be returned via this element. All JavaScript will also be transmitted via this element. If the first argument is a rule object, it will simply be added to this element. If it is a string, it is assumed that you want to create a rule which is linked to this element. Each rule can only be assigned to one element, but that element does not need to be used by the rule. For example: an element might validate two elements in a group, but if the element is added to the group, then any errors will be displayed at the group level.
Parameters:
|
mixed |
$rule: |
The rule to add |
|
|
$message: |
|
|
|
$arg2: |
|
|
|
$arg3: |
|
|
|
$arg4: |
|
|
|
$arg5: |
|
|
|
$arg6: |
|
API Tags:
Assign this element's parent
Parameters:
|
object Parent |
$parent: |
to assign |
API Tags:
mixed autoAK(
string
$lbl, string
$ak
)
|
|
Generates an access key and updated label
Uses an access key to generate a marked up label. If access key is simply true, it generates an access key by searching through the chars of the label for the first one that is a regular char ([a-z0- 9]) and is not already in use. If none are found, numbers starting from the left side of the std keyboard are used.
Parameters:
|
string |
$lbl: |
Label |
|
string |
$ak: |
Requested access key |
API Tags:
| Return: | Array of updated label if possible, null otherwise |
| Usedby: | SForm_Element::getLabelHtml() |
| Access: | protected |
| Uses: | markupLabelAK() - Markup the label with the found key |
| Uses: | $accesskeys - Determine which keys are used |
object Created createRule(
string
$rule, [string
$message = null], [
$arg2 = null], [
$arg3 = null], [
$arg4 = null], [
$arg5 = null], [
$arg6 = null]
)
|
|
Creates & returns a rule
Parameters:
|
string |
$rule: |
Name of the rule |
|
string |
$message: |
Error message for the rule |
|
|
$arg2: |
|
|
|
$arg3: |
|
|
|
$arg4: |
|
|
|
$arg5: |
|
|
|
$arg6: |
|
API Tags:
| Return: | rule |
| Access: | protected |
void filter(
mixed
$callback
)
|
|
Apply a filter to the value
This is passed a callback function which applies some sort of filter to any value returned from getValue(). Any additonal arguments to this function will be appended to the arguments of the callback function. This cannot be called after validate() or render(), because the element is locked.
Parameters:
|
mixed |
$callback: |
Callback function |
API Tags:
string filterValue(
$val
)
|
|
Filters the value
Filters a value that is about to be returned from getValue().
Parameters:
API Tags:
void freeze(
[boolean
$bool = true]
)
|
|
Set if this element is frozen
Parameters:
|
boolean |
$bool: |
Is it frozen? |
API Tags:
Redefined in descendants as:
string getAttribute(
string
$attr
)
|
|
Get an attribute in $this
Parameters:
|
string |
$attr: |
Attribute to get |
API Tags:
Do we have any errors?
Did this element's validation generate any errors? If it did, return those errors as an HTML string. Each error is seperated by a ' ' tag.
API Tags:
| Return: | Any errors that were produced |
| Access: | public |
This is the page-wide unique ID
The Global ID is a page-unique id which is a concatination of the parent's Global ID, a colon, and the Local ID. This is done so that element groups can be nested arbitrarily deeply with non-uniqe IDs (ex: an array: '0','1','2'...). The Global ID is used as the 'id' HTML attribute and is typically also used as the 'name' attribute. The Global ID cannot be determined until the element is "rooted" to a SForm object.
API Tags:
| Return: | A globally usable ID |
| Access: | public |
Redefined in descendants as:
Return the label string (no markup)
API Tags:
| Return: | The raw label |
| Access: | public |
| Uses: | $label |
Redefined in descendants as:
void getLabelHtml(
[mixed
$accesskey = true]
)
|
|
Return the label with markup added
Generates the marked up 'label' tag. This includes the 'for' attribute, which links this label to the appropriate form element. The label allows software (and the people who use it) to understand the layout of your form without being able to view it. If the element is required, the value of option 'requiredSym' is appended to the beginning of the label. If requested, an access key is generated, and added to the tag. The access key links this label to a specific element. Not only does an access key make the page more friendly for people with motor disabilities, it will now be easier to quickly navigate the fields in your form for data entry. Access keys can be enabled, set, or disabled via the passed parameters. By default, $ak is true and an access key is generated. If a char is passed, that char is used as the access key and the label is marked up approriately. If false is passed, no access key is used.
Parameters:
|
mixed |
$accesskey: |
Do we automatically generate an access key? |
API Tags:
Information Tags:
Redefined in descendants as:
A Locally usable ID
The local ID is the name that a parent uses to identify its child element.
API Tags:
mixed getRequest(
string
$val
)
|
|
Returns a value from the request
Parameters:
|
string |
$val: |
Value to retrieve |
API Tags:
| Return: | Value or null |
| Access: | protected |
Redefined in descendants as:
The value of this element
The value returned is the same as if the form was rendered, displayed, then submitted by the user, in its current state.
API Tags:
Is this element marked as frozen?
API Tags:
| Return: | Is this element frozen? |
| Access: | public |
| Uses: | $frozen |
Is this element required?
API Tags:
Locks & adds any last minute stuff
This is here to be overridden as needed by subclasses to add any rules, filters, and values immidiately before they are locked. Remember to check if it's already locked first, because an element may be locked more than once.
API Tags:
Redefined in descendants as:
Append this leaf element to the render queue
The renderer is passed to this element so it can call whichever method is wanted. (ie: toHtml(), toJavaScript(), and/or toString()).
Parameters:
|
object The |
$rend: |
renderer to use |
API Tags:
Redefined in descendants as:
void setAttribute(
string
$attr, [string
$value = null]
)
|
|
Set an attribute in $this
Parameters:
|
string |
$attr: |
Attribute to set |
|
string |
$value: |
Value to set (sets value = attribute if null) |
API Tags:
Redefined in descendants as:
void setDefault(
string
$value
)
|
|
Set the default value of this element
This sets the default value of this element. If there is a user-submitted value or a setValue(), it overrides this one.
Parameters:
|
string |
$value: |
Element's value. |
API Tags:
Redefined in descendants as:
void setValue(
string
$value
)
|
|
Set the value of this element
This sets the current value of the element, overriding any current value.
Parameters:
|
string |
$value: |
Element's value. |
API Tags:
Do we have any hidden tags to append?
Append hidden tags seperately from regular HTML tags so they can be collected at the end of the form. That way the visible part of the form is parsed and displayed to the user first. By default, hidden elements are only generated when this element is frozen.
API Tags:
Redefined in descendants as:
Create a HTML representation of this element
Creates a HTML tag appropriate to input a value for this element. At minimum, 'id' and 'name' attributes are included. Additonal attributes can be added via the methods appropriate for the element. Custom attributes can be added via setAttribute(). If this element is frozen, the string representation is returned instead of an input field.
API Tags:
Redefined in descendants as:
Close an open HTML tags
API Tags:
Redefined in descendants as:
Retrieve any JavaScript that should be run onsubmit
Locks the rules and iterates through them to produce a JavaScript string appropriate to be run on submission of the form.
API Tags:
How does this value look as a HTML string?
API Tags:
Redefined in descendants as:
void unsetAttribute(
string
$attr
)
|
|
Unset an attribute
Parameters:
|
string |
$attr: |
Attribute to unset |
API Tags:
Is this a valid element?
Performs server side validation using any of the added rules. Calls lock() to provide a chance to load any intrinsic rules.
API Tags:
Redefined in descendants as:
Was this form submitted?
API Tags:
| Return: | Has it been submitted? |
| Access: | public |
Redefined in descendants as:
|
|