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

Class: HtmlForm

Source Location: /HtmlForm.class.php

Class Overview


Main class for the whole HtmlForm-Framework, representing a Form itself.


Author(s):

  • Sebastian Schlapkohl

Version:

  • 1.0

Constants

Methods



Class Details

[line 60]
Main class for the whole HtmlForm-Framework, representing a Form itself.

To minimize the hassle of using this framework this is the only file that needs to be included into a project to make the whole framework known. All needed information and classes follow with this one.

To understand what you're doing: HtmlForm handles normal html4 data-input forms completely as php5-Objects, including all possible widgets and functionality. So by instantiating this class you actually create a form, in which you may insert everything you need for processing your data.

The features of this framework include validation, auto-masking, utf-8-handling, auto-tabindices, error display, and intelligent html-preformat to easily style later, unified result and value-handling, xhtml-rendering and much more.

Additionally HtmlForm also provides all its validation capabilites as on the fly functionality based on jQuery, individually configurable for each element.

For an extensive example see the index.php included in the full package.




Tags:

author:  Sebastian Schlapkohl
version:  1.0


[ Top ]


Class Methods


static method get [line 191]

static HtmlForm get( String $id)

Factory method for HtmlForms, returns new instance.

Factories are used to make instant chaining possible.




Tags:

return:  new HtmlForm-instance
access:  public


Parameters:

String   $id   html-id for the form

[ Top ]

method addCell [line 872]

HtmlForm addCell( )

Adds a new cell to the form.



Tags:

return:  method owner
see:  HtmlForm::setCells()
access:  public


[ Top ]

method addCssClasses [line 794]

HtmlForm addCssClasses( String $cssClasses)

Adds one or many css-classes to the forms 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 811]

HtmlForm addElement( $element, [uint $cell = 1])

Adds an element to the form.

You can never add directly to the form, but will automatically add to a cell, which a form always has a minimum of one of. Before adding elements to additional cells, be sure to add or define them beforehand.




Tags:

return:  method owner
access:  public


Parameters:

FormElement   $element   the element to add to the target cell
uint   $cell   the index of the cell in which to add the element, starts with 1 (default value as well)

[ Top ]

method doRender [line 1100]

String doRender( )

Compiles the whole form for output and returns the finished html-code-fragment.

Insert the result of this function into your page to use the form.




Tags:

return:  html-code for the form
access:  public


[ Top ]

method getElementByName [line 625]

FormElement/Array[FormElement] getElementByName( String $name, [Boolean $multiple = false])

Returns any form element added to the form by searching for it's name.

This search is strictly for names not ids. If an element needs to be searchable just give it a name by using FormElement::setName() if it doesn't get one by default.




Tags:

return:  the found element(s)
access:  public


Parameters:

String   $name   the name to search for
Boolean   $multiple   defines if more than one element should be returned, or just the first

[ Top ]

method getId [line 561]

String getId( )

Returns the set html-id of the form.



Tags:

return:  current form id
access:  public


[ Top ]

method getLanguage [line 609]

String getLanguage( )

Returns the set language of the form.



Tags:

return:  name of current form language
access:  public


[ Top ]

method getMethod [line 574]

String/Array[String] getMethod( [Boolean $returnAsArray = false])

Returns the set form method.

Also able to return the method as php-array, for direct use.




Tags:

return:  either the current method as a string (default) or the fitting php-method-array
access:  public


Parameters:

Boolean   $returnAsArray   defines if the result should be the php-method-array itself

[ Top ]

method getPackagePath [line 550]

String getPackagePath( )

Returns the set package path.



Tags:

return:  current package path
see:  HtmlForm::setPackagePath()
access:  public


[ Top ]

method getTabIndex [line 598]

uint getTabIndex( )

Returns the set tabindex for the form.



Tags:

return:  current tabindex of the form
access:  public


[ Top ]

method getValueSet [line 671]

FormValueSet getValueSet( [ $addedSet = null])

Returns the complete valueset of a form.

A valueset gathers all contained values of a form in one consistent object, that can be much more easily parsed than dealing with every input-characteristic manually. Missing values are null, everything else is a string or array of strings.




Tags:

return:  the complete current valueset of the form
see:  FormValueSet
access:  public


Parameters:

FormValueSet   $addedSet   a valueset to start on

[ Top ]

method hasBeenSent [line 745]

Boolean hasBeenSent( )

Answers if the form has already been sent or not.

This is a relative information since the method searches for fitting GET- or POST-information. If you changed the action or created data under the name of the form-id you may interrupt this mechanism.




Tags:

return:  yes/no answer
access:  public


[ Top ]

method incTabIndex [line 859]

HtmlForm incTabIndex( )

Increases the internal tabindex-counter of the form by one.

Should not be called externally. This is mostly a helper method for the form widgets.




Tags:

return:  method owner
access:  public


[ Top ]

method insertElementAfter [line 830]

HtmlForm insertElementAfter( String $targetElementName, $element)

Adds an element directly after another one in the form.

The target element is identified by name alone. Terminates after the first insert.




Tags:

return:  method owner
access:  public


Parameters:

String   $targetElementName   name of the element to insert after
FormElement   $element   the element to insert

[ Top ]

method isValid [line 693]

Boolean isValid( )

Answers if the form is currently in a valid state.

This value is always based on the currently active validators of the form widgets. If no validators exist, the form ist always valid.




Tags:

return:  yes/no answer
access:  public


[ Top ]

method javascriptValidationIsSuppressed [line 759]

Boolean javascriptValidationIsSuppressed( )

Answers if the form actively suppresses possibly set JS-validation in it.



Tags:

return:  yes/no answer
access:  public


[ Top ]

method prepareJavascriptValidation [line 506]

HtmlForm prepareJavascriptValidation( )

Tells the form to prepare everything concerning Javascript to use the jQuery-based Javascript-validation for form elements with activated JS-validation.

At least one form per page should do this, to be able to use JS-validation. You can leave this out for additional forms, but leaving it won't hurt dramatically either.

The method includes an own version of jQuery, which is protected by an own namespace and a JS-environment, docked to a HTMLFORM global-JS-variable.




Tags:

return:  method owner
access:  public


[ Top ]

method printFloatBreak [line 914]

String printFloatBreak( )

Returns the html-code used by widgets to mark the end of a supposed row in a form.

This fragment is meant to break any occured floating in the row, to prevent displaying several logical rows in the same optical row. Simply spoken: This brutally ends a row.

For internal use by form-widgets.




Tags:

return:  html-fragment to end a form-row
access:  public


[ Top ]

method printSlash [line 899]

String printSlash( )

Returns a the character to attach to the xhtml-presentation of tags.

Should not be called externally. For internal use by the form-widgets.




Tags:

return:  xhtml-slash-character
access:  public


[ Top ]

method setAction [line 263]

HtmlForm setAction( String $action)

Set the html-action of the form.

Normally an empty string to enable form-submit-cycling.




Tags:

return:  method owner
access:  public


Parameters:

String   $action   value of the html-action-attribute

[ Top ]

method setCells [line 394]

HtmlForm setCells( uint $cellCount)

Sets the amount of cells to create for the form. Each cell represents a logical container for parts of the form.

This can serve the purpose of applying different styles to each cell for example, or to group widgets for easier javascript-manipulation.

This method doesn't recreate all cells but expands or contracts existing ones.




Tags:

return:  method owner
access:  public


Parameters:

uint   $cellCount   amount of cells to create

[ Top ]

method setCharsetLatin [line 315]

HtmlForm setCharsetLatin( )

Tells the form to explicitly use standard english encoding, without any exotic special characters.

By setting this you also disable binary-safe string operations for all values.




Tags:

return:  method owner
access:  public


[ Top ]

method setCharsetUtf8 [line 302]

HtmlForm setCharsetUtf8( )

Tells the form to handle all data and values of the form as utf-8-encoded.

This is the default setting, which should only be changed for the right reasons. Encoding does not only change the charset-attribute but changes the whole way the form handles data in encoding critical operations.




Tags:

return:  method owner
access:  public


[ Top ]

method setCssClasses [line 362]

HtmlForm setCssClasses( String $cssClasses)

Sets the html-class-attribute for the form as a whole.

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 form

[ Top ]

method setEnctype [line 333]

HtmlForm setEnctype( String $enctype)

Sets the encoding type for the form. All standard values are allowed here, other values will be ignored.

Look up the specifications if you are unsure what the usual values might be.

This setting is normally necessary for enabling file-uploads by setting this to "multipart/form-data", to allow mixed normal fields and upload fields.




Tags:

return:  method owner
access:  public


Parameters:

String   $enctype   encoding type for the form

[ Top ]

method setExplanation [line 434]

HtmlForm setExplanation( unknown_type $explanation)

Sets an explanation text for the form, which in put in a fitting container on top of the form, below the headline (if one is defined).

This is a convenience method, which also allows easier adaptation of the html-view for different forms, that can be displayed at the same spot.




Tags:

return:  method owner
access:  public


Parameters:

unknown_type   $explanation  

[ Top ]

method setHeadline [line 418]

HtmlForm setHeadline( String $headline)

Sets a headline for the form, which is put in a fitting container on top of the form.

This is a convenience method, which also allows easier adaptation of the html-view for different forms, that can be displayed at the same spot.




Tags:

return:  method owner
access:  public


Parameters:

String   $headline   headline for the form

[ Top ]

method setLanguage [line 235]

HtmlForm setLanguage( String $language)

Sets the language to use in error messages. Form uses corresponding dictionary in "./messages".

Add new ones to enable other values aside from "english" and "german"




Tags:

return:  method owner
access:  public


Parameters:

String   $language   the name of the language to use

[ Top ]

method setMethodGet [line 287]

HtmlForm setMethodGet( )

Tells the form to send all data as GET and sets the html-method-attribute.



Tags:

return:  method owner
access:  public


[ Top ]

method setMethodPost [line 275]

HtmlForm setMethodPost( )

Tells the form to send all data as POST and sets the html-method-attribute.



Tags:

return:  method owner
access:  public


[ Top ]

method setMultipartFormData [line 348]

HtmlForm setMultipartFormData( )

Set the encoding to the most common setting, which is multipart/form-data. This setting is needed if you include file inputs in your form, otherwise the files will not be transferred to the server.



Tags:

return:  method owner
access:  public


[ Top ]

method setPackagePath [line 208]

HtmlForm setPackagePath( String $packagePath)

Sets the path to HtmlForm-package relative to the executing php-file to make usage of package assets such as javascripts and images possible (needed for special widgets such as datetime picker)



Tags:

return:  method owner
access:  public


Parameters:

String   $packagePath   relative path to HtmlForm-package

[ Top ]

method setTabIndex [line 377]

HtmlForm setTabIndex( uint $tabIndex)

Sets the tabindex of the form itself. All widgets of the form will get tabindices according to this value.

By setting this value you can ensure a correct flow ob tabindices even if the form doesn't provide the first input on the page.




Tags:

return:  method owner
access:  public


Parameters:

uint   $tabIndex   tabindex of the form itself

[ Top ]

method setXhtml [line 221]

HtmlForm setXhtml( )

Sets xhtml-rendering-mode for the form. Form renders as html4 per default.



Tags:

return:  method owner
access:  public


[ Top ]

method showCustomMessages [line 470]

HtmlForm showCustomMessages( [String $title = ''], [Boolean $show = true])

Defines if custom error messages should be displayed above the form or not.

Custom error messages are defined by the developer by defining error messages specifically for certain validators, or by setting the standard messages of a certain widget to be treated as custom. If these messages are activated you will get a selective and individual error output, which has to be defined manually.




Tags:

return:  method owner
access:  public


Parameters:

String   $title   title text above current error messages
Boolean   $show   show custom messages yes/no

[ Top ]

method showMessages [line 450]

HtmlForm showMessages( [String $title = ''], [Boolean $show = true])

Defines if standard error messages should be displayed above the form or not.

Standard error messages are taken out of the "./messages"-dictionaries and give detailed information about failed validators on form widgets. If these messages are activated, you will get a very verbose error ouptut.




Tags:

return:  method owner
access:  public


Parameters:

String   $title   title text above current error messages
Boolean   $show   show all messages yes/no

[ Top ]

method suppressJavascriptValidation [line 519]

HtmlForm suppressJavascriptValidation( )

Deactivates the execution of all JS-validation, no matter if any elements have this activated, or the form was told to prepare for it. No JS-environment will be printed and no validation code for elements will be printed.



Tags:

return:  method owner
access:  public


[ Top ]

method suppressJqueryInclude [line 535]

HtmlForm suppressJqueryInclude( )

Suppresses the inclusion of HtmlForm's own jQuery version and thereby sets the forms to rely on an already included, compatible, external version. HtmlForm relies on $ being present in that case.

Use this method to prevent double includes for more or less identical jQuery-versions, which may already be part of the site.




Tags:

return:  method owner
access:  public


[ Top ]

method useExternalFormDeclaration [line 249]

HtmlForm useExternalFormDeclaration( )

Tells the form to use an external form declaration (first around the rendered code) and not to render an own.

Useful if the form needs to be integrated into a bigger one or if special setting in the form tag are needed, which cannot be provided by the existing methods.




Tags:

return:  method owner
access:  public


[ Top ]

method useReducedErrorMarking [line 487]

HtmlForm useReducedErrorMarking( )

Sets the error marking in the form to reduced highlighting.

Normally the whole widget would be marked, including label, container and everything. The reduced mode only marks the inputs themselves, leaving the surroundings out. This ist especially useful if your form is rather compact and you don't want to mark half the form area for every error.




Tags:

return:  method owner
access:  public


[ Top ]

method usesExternalFormDeclaration [line 718]

Boolean usesExternalFormDeclaration( )

Answers if the form is currently set to use an external form declaration instead of an own one.



Tags:

return:  yes/no answer
see:  HtmlForm::useExternalFormDeclaration()
access:  public


[ Top ]

method usesReducedErrorMarking [line 731]

Boolean usesReducedErrorMarking( )

Answers if the form is currently set to only use reduced error marking for occuring validation errors.



Tags:

return:  yes/no answer
see:  HtmlForm::useReducedErrorMarking()
access:  public


[ Top ]

method usesUtf8 [line 705]

Boolean usesUtf8( )

Answers if the form is currently using utf-8 for value encoding.



Tags:

return:  yes/no answer
see:  HtmlForm::setCharsetUtf8()
access:  public


[ Top ]

method validate [line 773]

Boolean validate( )

Starts the form-validation for every contained widget and calculates the validity for every value leading to the overall validity for the form as a whole.



Tags:

return:  form is valid yes/no
access:  public


[ Top ]


Class Constants

CELLCLASS =  'htmlform_cell'

[line 72]

css-class for HtmlForm-cells


[ Top ]

CELLCLASS_FIRST =  'htmlform_cell_first'

[line 78]

css-class for first HtmlForm-cell


[ Top ]

CELLCLASS_LAST =  'htmlform_cell_last'

[line 84]

css-class for last HtmlForm-cell


[ Top ]

EXPLANATIONCLASS =  'htmlform_formexplanation'

[line 96]

css-class for the form explanation


[ Top ]

FLOATBREAKCLASS =  'htmlform_floatbreak'

[line 114]

css-class for float-breaking construct used between widgets of a form


[ Top ]

FORMCLASS =  'htmlform'

[line 66]

css-class for HtmlForm-forms


[ Top ]

HEADLINECLASS =  'htmlform_formheadline'

[line 90]

css-class for the form headline


[ Top ]

MESSAGESCLASS =  'htmlform_messages_div'

[line 102]

css-class for form messages


[ Top ]

MESSAGESTITLECLASS =  'htmlform_messages_title_div'

[line 108]

css-class for title of form messages


[ Top ]



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