phpDocumentor SForm
[ class tree: SForm ] [ index: SForm ] [ all elements ]

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:
Abstract:  
Access:  public

Properties

Methods

[ Top ]
Direct descendents
Child Class Description
SForm_Container A container holds one or more elements
SForm_Elm_Hidden The hidden element
SForm_Elm_Checkable A base for checkbox or radio elements
SForm_Elm_Text A text element
SForm_Elm_Textarea A textarea element
SForm_Elm_Button A button element
SForm_Elm_Select A select list
SForm_Elm_Header A header element

[ Top ]
Property Summary
static integer   $defId   Number the elements if not given an ID
boolean   $addName   Should we add the 'name' attribute?
array   $attributes   Attributes for this tag
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?

[ Top ]
Method Summary
static string   escHtml()   Escape HTML in a consistant manner
static string   getAttributesString()   Creates an HTML attribute string from an array
static string   getOption()   Get a global option
static void   setOption()   Set 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
void   assignParent()   Assign this element's parent
mixed   autoAK()   Generates an access key and updated label
object Created   createRule()   Creates & returns a rule
void   filter()   Apply a filter to the value
string   filterValue()   Filters the value
void   freeze()   Set if this element is frozen
string   getAttribute()   Get an attribute in $this
string   getErrorHtml()   Do we have any errors?
string   getGlobalId()   This is the page-wide unique ID
string   getLabel()   Return the label string (no markup)
void   getLabelHtml()   Return the label with markup added
string   getLocalId()   A Locally usable ID
mixed   getRequest()   Returns a value from the request
mixed   getValue()   The value of this element
boolean   isFrozen()   Is this element marked as frozen?
boolean   isRequired()   Is this element required?
void   lock()   Locks & adds any last minute stuff
void   render()   Append this leaf element to the render queue
void   setAttribute()   Set an attribute in $this
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   toHtmlFin()   Close an open HTML tags
string   toJavaScript()   Retrieve any JavaScript that should be run onsubmit
string   toString()   How does this value look as a HTML string?
void   unsetAttribute()   Unset an attribute
boolean   validate()   Is this a valid element?
boolean   wasSubmitted()   Was this form submitted?

[ Top ]
Properties
static integer   $defId = 0 [line 326]

Number the elements if not given an ID

API Tags:
Access:  protected


[ Top ]
boolean   $addName = true [line 192]

Should we add the 'name' attribute?

API Tags:
Access:  protected


Redefined in descendants as:

[ Top ]
array   $attributes = array() [line 333]

Attributes for this tag

API Tags:
Usedby:  SForm_Element::getAttribute()
Usedby:  SForm_Elm_Text::setAttribute()
Usedby:  SForm_Element::unsetAttribute()
Usedby:  SForm_Element::setAttribute()
Usedby:  SForm_Element::toHtml()
Usedby:  SForm_Element::toHidden()
Access:  protected


[ Top ]
boolean   $emptyTag = true [line 185]

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:
Access:  protected


Redefined in descendants as:

[ Top ]
array   $errors = array() [line 290]

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:
Access:  protected


[ Top ]
array   $filters = array() [line 298]

A list of filter callbacks

API Tags:
Access:  protected
See:  SForm_Element::filter()


[ Top ]
boolean   $locked = false [line 255]

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:
Usedby:  SForm_Element::addRule()
Usedby:  SForm_Element::lock()
Access:  protected


[ Top ]
object   $parent = null [line 202]

What is the parent to this element?

This points to some subclass of SForm_Container. It is set in SForm_Container::addElement().

API Tags:
Usedby:  SForm_Element::assignParent()
Access:  protected


[ Top ]
boolean   $required = false [line 266]

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:
Usedby:  SForm_Element::isRequired()
Access:  protected


[ Top ]
array   $rules = array() [line 244]

Rules to apply to this element

API Tags:
Access:  protected


[ Top ]
string   $tag = 'input' [line 174]

This is the element's tag ('input', 'select', 'form', etc) and should be set by the children as needed.

API Tags:
Access:  protected


Redefined in descendants as:

[ Top ]
boolean   $validated = false [line 276]

Has this element been validated?

Validated elements have a finished $errors array and will not be validated again.

API Tags:
Access:  protected


[ Top ]
boolean   $valueSet = false [line 209]

Has the value for this element been set?

API Tags:
Usedby:  SForm_Element::setValue() - Overrides any current value
Usedby:  SForm_Element::getValue() - Is the current value overridden by setValue?
Access:  protected


[ Top ]
Methods
static method escHtml  [line 956]

  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


[ Top ]
static method getAttributesString  [line 942]

  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


[ Top ]
static method getOption  [line 886]

  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


[ Top ]
static method setOption  [line 866]

  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


[ Top ]
Constructor __construct  [line 421]

  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:
Access:  public
Usedby:  SForm_Elm_Hidden::__construct()
See:  SForm_Element::getLabelHtml()
See:  SForm_Element::getLabel()
See:  SForm_Element::getLocalId()
See:  SForm_Element::getGlobalId()

Information Tags:
Link:  http://www.w3.org/TR/html4/types.html#h-6.2

Redefined in descendants as:

[ Top ]
addRule  [line 997]

  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:
Return:  added rule
Access:  public
Uses:  SForm_Rule::assignParent()
Uses:  SForm_Element::$locked


[ Top ]
assignParent  [line 1187]

  void assignParent( SForm_Container $parent  )

Assign this element's parent

Parameters:
object Parent   $parent:  to assign

API Tags:
Access:  protected
Uses:  SForm_Element::$parent
See:  SForm_Container::addElement()


[ Top ]
autoAK  [line 619]

  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


[ Top ]
createRule  [line 1047]

  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


[ Top ]
filter  [line 1091]

  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:
Access:  public


[ Top ]
filterValue  [line 529]

  string filterValue( $val  )

Filters the value

Filters a value that is about to be returned from getValue().

Parameters:
   $val: 

API Tags:
Return:  Filtered value
Access:  protected
See:  SForm_Element::getValue()


[ Top ]
freeze  [line 1156]

  void freeze( [boolean $bool = true]  )

Set if this element is frozen

Parameters:
boolean   $bool:  Is it frozen?

API Tags:
Usedby:  SForm_Container::freeze()
Access:  public
Uses:  $frozen


Redefined in descendants as:

[ Top ]
getAttribute  [line 927]

  string getAttribute( string $attr  )

Get an attribute in $this

Parameters:
string   $attr:  Attribute to get

API Tags:
Return:  Attribute's value
Access:  public
Uses:  SForm_Element::$attributes


[ Top ]
getErrorHtml  [line 1108]

  string getErrorHtml( )

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


[ Top ]
getGlobalId  [line 465]

  string getGlobalId( )

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:

[ Top ]
getLabel  [line 715]

  string getLabel( )

Return the label string (no markup)


API Tags:
Return:  The raw label
Access:  public
Uses:  $label


Redefined in descendants as:

[ Top ]
getLabelHtml  [line 677]

  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:
Access:  public
Uses:  SForm_Element::autoAK()

Information Tags:
Link:  http://alistapart.com/articles/accesskeys/
Link:  http://www.webstandards.org/learn/tutorials/accessible-forms/beginner/

Redefined in descendants as:

[ Top ]
getLocalId  [line 487]

  string getLocalId( )

A Locally usable ID

The local ID is the name that a parent uses to identify its child element.


API Tags:
Return:  A locally usable ID
Usedby:  SForm::getGlobalId()
Access:  public


[ Top ]
getRequest  [line 1201]

  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:

[ Top ]
getValue  [line 502]

  mixed getValue( )

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:
Return:  Element's current value
Usedby:  SForm_Element::toString()
Access:  public
Uses:  SForm_Element::$valueSet - Is the current value overridden by setValue?
See:  SForm_Element::setDefault()
See:  SForm_Element::setValue()


[ Top ]
isFrozen  [line 1166]

  boolean isFrozen( )

Is this element marked as frozen?


API Tags:
Return:  Is this element frozen?
Access:  public
Uses:  $frozen


[ Top ]
isRequired  [line 1176]

  boolean isRequired( )

Is this element required?


API Tags:
Return:  True if this element is required
Access:  public
Uses:  SForm_Element::$required


[ Top ]
lock  [line 729]

  void lock( )

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:
Usedby:  SForm_Element::validate()
Usedby:  SForm_Element::toJavaScript()
Access:  protected
Uses:  SForm_Element::$locked


Redefined in descendants as:

[ Top ]
render  [line 971]

  void render( SForm_Renderer $rend  )

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:
Usedby:  SForm_Container::render()
Access:  protected
Uses:  SForm_Renderer::append()


Redefined in descendants as:

[ Top ]
setAttribute  [line 901]

  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:
Access:  public
Uses:  SForm_Element::$attributes


Redefined in descendants as:

[ Top ]
setDefault  [line 561]

  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:
Access:  public
See:  SForm_Element::setValue()


Redefined in descendants as:

[ Top ]
setValue  [line 547]

  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:
Access:  public
Uses:  SForm_Element::$valueSet - Overrides any current value
See:  SForm_Element::setDefault()


[ Top ]
toHidden  [line 826]

  string toHidden( )

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:
Return:  HTML of the hidden element
Access:  public
Uses:  SForm_Element::$attributes


Redefined in descendants as:

[ Top ]
toHtml  [line 772]

  string toHtml( )

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:
Return:  HTML
Access:  public
Uses:  SForm_Element::$attributes
See:  SForm_Element::setAttribute()


Redefined in descendants as:

[ Top ]
toHtmlFin  [line 805]

  string toHtmlFin( )

Close an open HTML tags


API Tags:
Return:  The HTML needed to close this element
Access:  public
See:  SForm_Element::toHtml()


Redefined in descendants as:

[ Top ]
toJavaScript  [line 744]

  string toJavaScript( )

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:
Return:  Rendered JavaScript
Access:  public
Uses:  SForm_Rule::toJavaScript()
Uses:  SForm_Element::lock()


[ Top ]
toString  [line 850]

  string toString( )

How does this value look as a HTML string?


API Tags:
Return:  HTML
Uses:  SForm_Element::getValue()


Redefined in descendants as:

[ Top ]
unsetAttribute  [line 916]

  void unsetAttribute( string $attr  )

Unset an attribute

Parameters:
string   $attr:  Attribute to unset

API Tags:
Access:  public
Uses:  SForm_Element::$attributes


[ Top ]
validate  [line 1130]

  boolean validate( )

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:
Return:  Returns true if no errors are found.
Usedby:  SForm_Container::validate()
Access:  protected
Uses:  SForm_Rule::toHtml()
Uses:  SForm_Element::lock()


Redefined in descendants as:

[ Top ]
wasSubmitted  [line 1215]

  boolean wasSubmitted( )

Was this form submitted?


API Tags:
Return:  Has it been submitted?
Access:  public


Redefined in descendants as:

[ Top ]

Documentation generated on Mon, 09 Apr 2007 19:08:30 -0500 by phpDocumentor 1.3.0