Class: SForm
Source Location: /SForm.php
Class SForm
Inherited Properties, Constants, and Methods
Property Summary
| string |
$tag |
Why yes, this is a form |
Method Summary
| object Added |
addGroup() |
Create a group and add it to this form |
| void |
display() |
Prints this form to std out |
| string |
getGlobalId() |
All children of this form inheret their IDs from it. |
| mixed |
getRequest() |
Returns a value from the request |
| void |
process() |
Process the results of the form |
| void |
render() |
Renders a form with the provided renderer |
| void |
setDefaults() |
Set the default values of local elements |
| array |
toArray() |
Returns a nested array of all returned values |
Properties
Defaults are stored here
API Tags:
Why yes, this is a form
API Tags:
Redefinition of:
- SForm_Element::$tag
- This is the element's tag ('input', 'select', 'form', etc) and should be set by the children as needed.
Are we tracking the submit?
API Tags:
Methods
SForm __construct(
string
$id, [string
$method = 'post'], [string
$action = ''], [array
$attributes = null], [boolean
$trackSubmit = true]
)
|
|
Create a form
The ID parameter sets both the Global ID and the Local ID to be the same, since we are at the top level. All children of this form will use this ID as a prefix to their Global IDs. The method determines how we will send the data that is input. A 'get' method sends the data in the URL after a '?' and 'post' sends the data in the body of the HTTP request. An advantage of using 'get' is the results of the submission can be book marked. A disadvantage of using 'get' is that a form can be maliciously submitted without the user's knowledge by making them access the URL (ex: an embedded imag). 'get' requests are also awkward for large amounts of data. The action is what URL to send the data to. Generally you want to send the data back to the original URL so you can continue processing it and present errors if needed. Include extra attributes if you feel lucky. $trackSubmit inserts an extra hidden element. If this element isn't included in the submission, it is ignored. It defaults to true. Be careful when setting this to false, because the submission may then validate without a button ever being clicked. You might want to add a required rule to prevent this from happening. Changes from HTML_QuickForm: $target has been removed because it is not in XHTML 1.1. Use $attributes if you wish to add it back. $action is required in XHTML 1.1, so if one isn't provided, $_SERVER ['SCRIPT_URL'] is used. $trackSubmit has been set to true by default, because otherwise a form without required elements may validate without being submitted. $id does not apply a 'name' attribute to the form because this is illegal in XHTML 1.1.
Parameters:
|
string |
$id: |
This form's ID |
|
string |
$method: |
Method attribute of the form ('post' or 'get') |
|
string |
$action: |
Action attribute of the form |
|
array |
$attributes: |
Custom attributes for this form |
|
boolean |
$trackSubmit: |
Track whether this form was submitted. |
API Tags:
Redefinition of:
- SForm_Element::__construct()
- Construct with an identity. Optionally add a label and more attributes.
object Added addGroup(
array
$elements, [string
$id = null], [string
$label = null]
)
|
|
Create a group and add it to this form
This is depreciated because you can just do this yourself by creating a group (or fieldset) and adding to the form via SForm::. It's less confusing, also.
Parameters:
|
array |
$elements: |
Elements in group |
|
string |
$id: |
Group name |
|
string |
$label: |
Group label |
API Tags:
| Return: | group |
| Access: | public |
| Deprecated: | |
void addRuleDep(
mixed
$element, string
$message, string
$type, [string
$format = ''], [string
$validation = 'server']
)
|
|
Add a rule to given field(s)
Please use addRule() instead. This is only here for compatability reasons.
Parameters:
|
mixed |
$element: |
Element name(s) |
|
string |
$message: |
Error message |
|
string |
$type: |
Type of rule |
|
string |
$format: |
Extra data |
|
string |
$validation: |
Where to preform validation |
API Tags:
| Access: | public |
| Deprecated: | |
void display(
[object Renderer
$rend = null]
)
|
|
Prints this form to std out
Parameters:
|
object Renderer |
$rend: |
to use |
API Tags:
string exportValue(
string
$name
)
|
|
Returns an element's value
Parameters:
|
string |
$name: |
Element to retrieve value for |
API Tags:
| Return: | Element's value |
| Access: | public |
| Deprecated: | |
object Requested getGlobalElement(
string
$id
)
|
|
Get an element by its Global ID
Retrieves an element based on it's Global ID. When at all possible, I'd suggest that you retrieve elements via getElement().
Parameters:
API Tags:
| Return: | element (or null) |
| Access: | public |
Redefinition of:
- SForm_Container::getGlobalElement()
- Returns an element using the Global ID
All children of this form inheret their IDs from it.
When parent::getGlobalId() is called on a child, it calls its parent's getGlobalId() method and appends the results to its own Local ID. When the calling reaches the SForm level, it's at the root and there are no more parents, so the Local ID is returned.
API Tags:
Redefinition of:
- SForm_Element::getGlobalId()
- This is the page-wide unique ID
mixed getRequest(
string
$val
)
|
|
Returns a value from the request
Parameters:
|
string |
$val: |
Value to retrieve |
API Tags:
| Return: | Value or null |
| Access: | protected |
Redefinition of:
- SForm_Element::getRequest()
- Returns a value from the request
void process(
mixed
$callback
)
|
|
Process the results of the form
This method is depreciated because it takes less code and you gain more functionality if you just call the callback function yourself. Use toArray() to get the array, then call the function. That simple.
Parameters:
|
mixed |
$callback: |
Callback function |
API Tags:
| Access: | public |
| Deprecated: | |
Renders a form with the provided renderer
Render the form using the given renderer. If any defaults have been applied using setDefaults(), they are applied to the local elements here.
Parameters:
|
object The |
$rend: |
renderer to use |
API Tags:
Redefinition of:
- SForm_Container::render()
- Render this container and all elements in it
void setDefaults(
array
$defaults
)
|
|
Set the default values of local elements
This is here for HTML_QuickForm compatability. Please use SForm_Element::setDefault() instead. The reasoning is that all operations that are associated with perticular elements should operate on those elements, so this usage makes more sense. Also, when using QF, I found myself simply collecting values into an array at the same layer as element creation. After the the array was completed, I had to pass it through various layers of my program to finally set the defaults. Using SForm_Element::setDefault() makes things easier, also. Internally, element defaults are stored and set in render() using the SForm_Element::setDefault() method at render time. Any calls to SForm_Element::setDefault() will be overridden by the values in this form. The elements are retrieved using getElement(). This is due to the internal differences between QF and SForm. It doesn't mesh exactly with QuickForm, and you have been warned. Maybe you should use SForm_Element::setDefault() instead.
Parameters:
|
array |
$defaults: |
List of defaults for the elements. |
API Tags:
Returns a nested array of all returned values
Uses the default renderer to collect the values of all elements into an array. If objects are nested, then the array is nested also.
API Tags:
| Return: | Values of this form in an array. |
| Access: | public |
| Uses: | SForm_Renderer |
Is this valid?
Validates this form. Keep in mind that no rules can be added after an element is validated because that would invalidate the validation. If there was no request submitted, it is assumed that validation is not passed. Rules can be added via addRule().
API Tags:
Redefinition of:
- SForm_Container::validate()
- Is this valid?
Was this form submitted?
API Tags:
| Return: | Has it been submitted? |
| Access: | public |
Redefinition of:
- SForm_Element::wasSubmitted()
- Was this form submitted?
|
|