formelements
[ class tree: formelements ] [ index: formelements ] [ all elements ]

Class: FormElement

Source Location: /HtmlForm.FormElement.absclass.php

Class Overview


Abstract parent class for all widgets / elements contained in a form-object.


Author(s):

  • Sebastian Schlapkohl

Version:

  • 1.0

Variables

Constants

Methods


Child classes:

AlignBlock
This formelement fulfills the purpose of being a visual gatherer for other formelements.
CustomHtml
CustomHtml is a formelement to provide a container for custom html-content to be used inside a form.
FieldSet
FieldSet provides the means to group formelements in a HtmlForm by using normal html-fieldsets.
InputButton
Wraps a common form-button.
InputCheckbox
Wraps a group of checkboxes.
InputHidden
Wraps a hidden input.
InputRadio
Wraps a group of radiobuttons.
InputSubmit
Wraps a form-submit-button.
InputText
Wraps a standard text-input.
Label
Wraps a label for the use in the direct vicinity of a formelement.
Select
Wraps a select.
TextArea
Wraps a textarea.

Class Details

[line 30]
Abstract parent class for all widgets / elements contained in a form-object.

Provides all basic functionality concerning traversing, structure-fit-in, basic html-attributes, validation to inheriting classes. Being a specialization of this class means being a barebone-widget with everything present, but specific functionality. If you want to write a new widget, be sure to inherit from this class or a already present widget.

This class also handles creation of error-messages and such side-tasks as auto-tabindices. In general this class handles all the annoying bits for the elements.

This class also holds standard print-methods for later rendering of the specialized widget. Look up an example in the present elements and do use them!




Tags:

author:  Sebastian Schlapkohl
version:  1.0
abstract:  


[ Top ]


Class Variables

$cssClasses =

[line 126]

The html-class-string of the element.



Tags:

access:  protected

Type:   String


[ Top ]

$disabled =

[line 150]

The html-enabled-state of the element.



Tags:

access:  protected

Type:   Boolean


[ Top ]

$id =

[line 108]

The html-id of the element.



Tags:

access:  protected

Type:   String


[ Top ]

$isValid =

[line 101]

The validity status of the element.



Tags:

access:  protected

Type:   Boolean


[ Top ]

$jsEventHandler =

[line 138]

Complete attribute string for a standard javascript-tag-eventhandler such as "onclick".



Tags:

access:  protected

Type:   String


[ Top ]

$label =

[line 132]

The text of the element label.



Tags:

access:  protected

Type:   String


[ Top ]

$masterElement =

[line 88]

The element into which the element has been inserted, if this was the case.



Tags:

access:  protected

Type:   FormElement


[ Top ]

$masterForm =

[line 82]

The form to which the element belongs.



Tags:

access:  protected

Type:   HtmlForm


[ Top ]

$name =

[line 114]

The html-name of the element.



Tags:

access:  protected

Type:   String


[ Top ]

$subElements =

[line 144]

The subelements of the element if the element has container character.



Tags:

access:  protected

Type:   Array[FormElement]


[ Top ]

$title =

[line 120]

The html-title of the element.



Tags:

access:  protected

Type:   String


[ Top ]

$validator =

[line 95]

The validator to validate the values of the element according to its rules.



Tags:

access:  protected

Type:   FormValidator


[ Top ]



Class Methods


constructor __construct [line 160]

FormElement __construct( String $name, [String $id = ''])

General abstract, hidden formelement constructor.

Initializes basic form values. Must be called at the beginning of specialized element constructors.




Tags:

access:  protected


Overridden in child classes as:

AlignBlock::__construct()
Hidden constructor.
CustomHtml::__construct()
Hidden constructor.
FieldSet::__construct()
Hidden constructor.
InputButton::__construct()
Hidden constructor.
InputReset::__construct()
Hidden constructor.
InputCheckbox::__construct()
Hidden constructor.
InputHidden::__construct()
Hidden constructor.
InputRadio::__construct()
Hidden constructor.
InputSubmit::__construct()
Hidden constructor.
InputImage::__construct()
Hidden constructor.
InputText::__construct()
Hidden constructor.
InputFile::__construct()
Hidden constructor.
InputPassword::__construct()
Hidden constructor.
JsDateTime::__construct()
Hidden constructor.
Label::__construct()
Hidden constructor.
Select::__construct()
Hidden constructor.
TextArea::__construct()
Hidden constructor.

Parameters:

String   $name   internal name of the element (also html-name if one is needed)
String   $id   html-id of the element

[ Top ]

method addCssClasses [line 532]

FormElement addCssClasses( String $cssClasses)

Adds one or many css-classes to the element's class-attribute.

This is simple string concatenation. You don't have to leave a blank at the start of the string to add.




Tags:

return:  method owner
access:  public


Parameters:

String   $cssClasses   the classes-string to add to the current one

[ Top ]

method addElement [line 546]

FormElement addElement( FormElement $element)

Adds a subelement to the element.

Is available but won't do anything for elements that have no container character.




Tags:

return:  method owner
access:  public


Parameters:

FormElement   $element   the element to add to the subelements

[ Top ]

method determineRefiller [line 593]

Array[String] determineRefiller( [Array[String]|null $refiller = array()])

Returns the supposed source of refill values.

Either the provided array will be taken, or the method tries to determine the element's data source by the method of the masterform. If that fails the refiller defaults to $_POST. For internal use. Doesn't need to be overwritten or extended.




Tags:

return:  refill source for element
access:  protected


Parameters:

Array[String]|null   $refiller   predetermined refill source for element

[ Top ]

method doRender [line 799]

void doRender( )

Returns the compiled html-code for the element.

Has to be implemented by specialized classes. Use the protected print-methods of this class to make life easier for you.




Tags:

abstract:  
access:  public


Overridden in child classes as:

AlignBlock::doRender()
Compiles and returns the html-fragment for the element including all subelements.
CustomHtml::doRender()
Compiles and returns the html-fragment for the element.
FieldSet::doRender()
Compiles and returns the html-fragment for the element including all subelements.
InputButton::doRender()
Compiles and returns the html-fragment for the element.
InputReset::doRender()
Compiles and returns the html-fragment for the element.
InputCheckbox::doRender()
Compiles and returns the html-fragment for the element.
InputHidden::doRender()
Compiles and returns the html-fragment for the element.
InputRadio::doRender()
Compiles and returns the html-fragment for the element.
InputSubmit::doRender()
Compiles and returns the html-fragment for the element.
InputImage::doRender()
Compiles and returns the html-fragment for the element.
InputText::doRender()
Compiles and returns the html-fragment for the element.
InputFile::doRender()
Compiles and returns the html-fragment for the element.
InputPassword::doRender()
Compiles and returns the html-fragment for the element.
JsDateTime::doRender()
Compiles and returns the html-fragment for the element.
Label::doRender()
Compiles and returns the html-fragment for the element.
Select::doRender()
Compiles and returns the html-fragment for the element.
SelectList::doRender()
Compiles and returns the html-fragment for the element.
TextArea::doRender()
Compiles and returns the html-fragment for the element.

[ Top ]

method getId [line 376]

String getId( )

Return the element's html-id.



Tags:

return:  the element's html-id
access:  public


[ Top ]

method getLabel [line 409]

String getLabel( )

Return the element's label text.



Tags:

return:  the element's label text
access:  public


[ Top ]

method getMasterElement [line 354]

FormElement getMasterElement( )

Return the currently connected owner element for the element.



Tags:

return:  the element's owner element or null
access:  public


[ Top ]

method getMasterForm [line 343]

HtmlForm getMasterForm( )

Returns the currently connected owner form for the element.



Tags:

return:  the element's owner form or null
access:  public


[ Top ]

method getName [line 387]

String getName( )

Return the element's html-name.



Tags:

return:  the element's html-name
access:  public


[ Top ]

method getSubElements [line 420]

Array[FormElement] getSubElements( )

Return all owned elements of this element.



Tags:

return:  all elements owned by this element
access:  public


[ Top ]

method getTitle [line 398]

String getTitle( )

Return the element's html-title.



Tags:

return:  the element's html-title
access:  public


[ Top ]

method getValidator [line 365]

FormValidator getValidator( )

Return the currently connected validator for the element.



Tags:

return:  the element's validator or null
access:  public


[ Top ]

method getValue [line 458]

null/String/Array[String] getValue( )

Returns the value of the element if there is any.

Has to be implemented by all form elements.




Tags:

return:  the value the element provides in the implementation
abstract:  
access:  public


Overridden in child classes as:

AlignBlock::getValue()
Since AlignBlock doesn't hold any value, this method will always return null.
CustomHtml::getValue()
Since CustomHtml doesn't hold any value, this method will always return null.
FieldSet::getValue()
Since FieldSet doesn't hold any value, this method will always return null.
InputButton::getValue()
Since InputButton doesn't hold any value, this method will always return null.
InputCheckbox::getValue()
Returns the current value of the element.
InputHidden::getValue()
Returns the currently set value of the element.
InputRadio::getValue()
Returns the current value of the element.
InputSubmit::getValue()
Returns if the submit-button was used for the last occurred form-submit.
InputImage::getValue()
Returns if the image_submit-button was used for the last occurred form-submit.
InputText::getValue()
Returns the current value of the element.
InputFile::getValue()
Returns the current value of the element.
Label::getValue()
Since Label doesn't hold any value, this method will always return null.
Select::getValue()
Returns the current value of the element.
TextArea::getValue()
Returns the current value of the element.

[ Top ]

method getValueSet [line 433]

FormValueSet getValueSet( [ $addedSet = null])

Returns the compiled valueset for this element including the elements owned by this one.



Tags:

return:  the comiled valueset of this element and its descendants
see:  FormValueSet
access:  public


Parameters:

FormValueSet   $addedSet   a valueset to start with instead of an empty one

[ Top ]

method insertElementAfter [line 567]

FormElement insertElementAfter( String $targetElementName, FormElement $element)

Searches the subelements of the element if present and inserts a given element after the first found one.

This method doesn't add an element right behind the element itself, but inserts one into the subelements if a match is found.

This method is available, but doesn't do anything for elements that have no container character.




Tags:

return:  method owner
access:  public


Parameters:

String   $targetElementName   the name of the subelement to search for
FormElement   $element   the element to insert into the subelements behind the found one

[ Top ]

method isValid [line 472]

Boolean isValid( )

Answers if the element is in a valid state at the moment.

Per default an element is always valid, if a validator is added it can't be valid until it has been validated according to the rules of the validator.




Tags:

return:  yes/no answer
access:  public


[ Top ]

method needsUtf8Safety [line 485]

Boolean needsUtf8Safety( )

Answers if the element needs to be treated with precautions according to possible utf-8 values.

This value is completely derived from the masterform if present, otherwise the value will be treated as utf-8 for security reasons.




Tags:

return:  yes/no answer
access:  protected


[ Top ]

method printCssClasses [line 659]

String printCssClasses( )

Compiles the html-class-attribute-string of the element.

Auto-includes an error-class if element is found invalid.




Tags:

return:  compiled attribute-string
access:  protected


[ Top ]

method printDisabled [line 741]

String printDisabled( )

Compiles the html-disabled-attribute-string of the element.



Tags:

return:  compiled attribute-string
access:  protected


[ Top ]

method printId [line 614]

String printId( )

Compiles the html-id-attribute-string of the element.



Tags:

return:  compiled attribute-string
access:  protected


[ Top ]

method printJavascriptEventHandler [line 717]

String printJavascriptEventHandler( )

Compiles html-javascript-eventhandler-string of the element.



Tags:

return:  compiled attribute-string
access:  protected


[ Top ]

method printJavascriptValidationCode [line 778]

String printJavascriptValidationCode( )

Grabs the compiled JS-validation-code for the element from its validator, if present and returns the code as a string.



Tags:

return:  JS-code to validate the element's values on the fly
access:  public


[ Top ]

method printMessages [line 754]

String printMessages( [Boolean $onlyCustomMessages = false])

Returns a string of all aggregated error messages of the element.

Makes only sense after a validation process took place.




Tags:

return:  aggregated error-message-string
access:  public


Parameters:

Boolean   $onlyCustomMessages   defines that only custom messages should be considered

[ Top ]

method printName [line 625]

String printName( )

Compiles the html-name-string of the element.



Tags:

return:  compiled attribute-string
access:  protected


[ Top ]

method printNameArray [line 636]

String printNameArray( )

Comiles the html-name-string of the element, if the element is part of a group of values.



Tags:

return:  compiled attribute-string
access:  protected


[ Top ]

method printTabIndex [line 728]

unit printTabIndex( )

Calculates current ongoing tabindex of the form, refreshes it and returns the proper value for the element.



Tags:

return:  tabindex of the element
access:  protected


[ Top ]

method printTitle [line 647]

String printTitle( )

Compiles the html-title-string of the element.



Tags:

return:  compiled attribute-string
access:  protected


[ Top ]

method printWrapperClasses [line 680]

String printWrapperClasses( )

Compiles a string of all classes for the tag-wrapper for the element's html-code.

Auto-includes an error-class if element is found invalid and error marking is set to full.




Tags:

return:  compiled wrapper classes
access:  protected


[ Top ]

method setCssClasses [line 269]

FormElement setCssClasses( String $cssClasses)

Sets the html-class-attribute for the element.

Use exactly the same notation you would use in html.




Tags:

return:  method owner
access:  public


Parameters:

String   $cssClasses   css-classes-string to use for the element

[ Top ]

method setDisabled [line 316]

FormElement setDisabled( )

Set the element disabled.



Tags:

return:  method owner
access:  public


Overridden in child classes as:

InputCheckbox::setDisabled()
Set the element disabled, or set single options disabled.
InputRadio::setDisabled()
Set the element disabled, or set single options disabled.
Select::setDisabled()
Set the element disabled, or set single options disabled.

[ Top ]

method setId [line 242]

FormElement setId( String $id)

Sets the html-id for this element.



Tags:

return:  method owner
access:  public


Parameters:

String   $id   html-id to use for this element

[ Top ]

method setJavascriptEventHandler [line 304]

FormElement setJavascriptEventHandler( String $handler, String $reaction)

Sets a javascript-handler for the element.

If you want to use such things as "onchange" or "onclick", you can set that with this method. At the moment only one handler per element is allowed, because this is supposed to be a comfortable way of inserting little quirks and not a programming interface. If you need to do complicated things, use raw javascript or jquery and reference the element by a fitting selector.




Tags:

return:  method owner
access:  public


Parameters:

String   $handler   the handler attribute
String   $reaction   the javascript-code to execute if handler fires

[ Top ]

method setLabel [line 285]

FormElement setLabel( string $label)

Inserts a label for the element.

This is not a label in the html-sense, but to be seen as a description for the purpose of the element. The label is rendered into an own tag before the widget.




Tags:

return:  method owner
see:  Label
access:  public


Parameters:

string   $label   text to display in the element-label

[ Top ]

method setMasterElement [line 209]

FormElement setMasterElement( FormElement $master)

Sets the owning element for an element.

Some elements can contain others, allowing a tree structure of the form object. Every element eventually knows the form it is in, but additionally knows which element contains it, if it is not directly put into the form. For internal use. Use element->addElement() instead.




Tags:

return:  method owner
access:  public


Parameters:

FormElement   $master   the formelement to set as owner of the element

[ Top ]

method setMasterForm [line 190]

FormElement setMasterForm( $master)

Sets the owning form for an element and by doing so inserts the element into the logical structure of the form.

For internal use. Use form->addElement() instead.




Tags:

return:  method owner
access:  public


Parameters:

HtmlForm   $master   the form this element belongs to

[ Top ]

method setTitle [line 255]

FormElement setTitle( String $title)

Sets the html-title for this element.



Tags:

return:  method owner
access:  public


Parameters:

String   $title   html-title to use for this element

[ Top ]

method setUsable [line 329]

FormElement setUsable( Boolean $expression)

Set the element usables or disabled based on an expression.



Tags:

return:  method owner
access:  public


Parameters:

Boolean   $expression   boolean expression to determine if element is usable

[ Top ]

method setValidator [line 226]

FormElement setValidator( $validator)

Sets a validator for a value-bearing element.

By doing so you render the element invalid by default. To get it valid again you have to validate the form it is in or the element itself. A validator can be set up with a set of rules for the value of the element. If one of those rules is broken the element is treated as being invalid.




Tags:

return:  method owner
see:  FormValidator
access:  public


Parameters:

FormValidator   $validator   the validator holding the rules to validate the elements value(s)

[ Top ]

method validate [line 505]

Boolean validate( )

Starts validation for the element and all subelements according to the rules laid out in the element's validator.

Calculates the compiled validity-state for the element and all descendants recursively. After this call, isValid() always returns the correct calculated state.

If element has no masterform at the moment of call the validators work on default settings.

This method must be overwritten in specialized classes and called at the beginning of the overwriting method.




Tags:

return:  element is valid yes/no
access:  public


Overridden in child classes as:

InputCheckbox::validate()
Starts the validation-process for the element.
InputHidden::validate()
Starts the validation-process for the element.
InputRadio::validate()
Starts the validation-process for the element.
InputText::validate()
Starts the validation-process for the element.
Select::validate()
Starts the validation-process for the element.
TextArea::validate()
Starts the validation-process for the element.

[ Top ]


Class Constants

ERRORCLASS =  'htmlform_error'

[line 48]

css-class for marking an element as invalid as specified by it's validator


[ Top ]

JSENABLEDCLASS =  'htmlform_jsenabled'

[line 73]

css-class for marking an element as enabled for js-validation


[ Top ]

MANDATORYCLASS =  'htmlform_mandatory'

[line 55]

css-class for marking an element as mandatory, if it is defined as such by a validator


[ Top ]

OPTIONALCLASS =  'htmlform_optional'

[line 61]

css-class for marking an element as optional, if it is defined as such by a validator


[ Top ]

UNVALIDATEDCLASS =  'htmlform_unvalidated'

[line 67]

css-class for marking an element as being unvalidated, if it is missing a validator


[ Top ]

WIDGETCLASS =  'htmlform_widget_div'

[line 42]

css-class for the container that includes everything directly related to the element itself


[ Top ]

WRAPCLASS =  'htmlform_row_div'

[line 36]

css-class for the row-div each form element is delivered in


[ Top ]



Documentation generated on Fri, 18 Jul 2014 16:31:57 +0200 by phpDocumentor 1.4.3