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

Class: SForm_Renderer

Source Location: /SForm.php

Class SForm_Renderer

Class Overview

Render only the values by default

The default renderer is useful for creating an array of the submitted values. The array can then be passed to a function that would enter it into a database, or it can be displayed out using http://www.php.net/var_dump.

Feel free to create your own renderer if these don't suit your needs.

Located in /SForm.php [line 2765]



		
				Author(s):
		
API Tags:
Usedby:  SForm::toArray()

Properties

Methods

[ Top ]
Direct descendents
Child Class Description
SForm_Renderer_HTML Render the form to plain (X)HTML
SForm_Renderer_Array Render the form to an array

[ Top ]
Property Summary
array   $currElms   Array that we are currently rendering
boolean   $errors   Were errors reported?
string   $hidden   Store the hidden elements in one string
string   $javascript   Rendered JavaScript, to be run onsubmit
mixed   $jsPostfix  
string   $jsPrefix   Error message in the JavaScript
boolean   $required   Were any elements required?
array   $stack   Array that holds rendered bits of elements

[ Top ]
Method Summary
void   append()   Append the current element's value to the tree
string   applyJavaScript()   Applies the rendered JavaScript to the given form
array   fetch()   We need to retrieve the resulting data
void   pop()   Move back down in the stack
void   push()   Move up a level in the stack
void   rendJavaScript()   Render the array of JavaScript into a script
void   startForm()   Start rendering the form

[ Top ]
Properties
array   $currElms = array() [line 2825]

Array that we are currently rendering

The elements in this array are all in the container that we are currently rendering.

API Tags:
Access:  protected


[ Top ]
boolean   $errors = false [line 2783]

Were errors reported?

API Tags:
Access:  protected


[ Top ]
string   $hidden = '' [line 2776]

Store the hidden elements in one string

Hidden elements will be collected to one location, because the user really doesn't know or care where we put them. The string could then be output at the end of the form, to give everything else the chance to render first.

API Tags:
Access:  protected


[ Top ]
string   $javascript = '' [line 2807]

Rendered JavaScript, to be run onsubmit

API Tags:
Access:  protected


[ Top ]
mixed   $jsPostfix = 'Please correct these fields.' [line 2815]
API Tags:
Access:  protected


[ Top ]
string   $jsPrefix = 'Invalid information entered.' [line 2814]

Error message in the JavaScript

API Tags:
Access:  protected


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

Were any elements required?

API Tags:
Access:  protected


[ Top ]
array   $stack = array() [line 2800]

Array that holds rendered bits of elements

As we move into and out of containers, we should push and pop (respectively) off of this stack.

API Tags:
Access:  protected


[ Top ]
Methods
append  [line 2847]

  void append( SForm_Element $elm  )

Append the current element's value to the tree

Here we are interested only in collecting the value of elements, but in subclasses we would probably want to collect more information about the element that we are visiting.

Parameters:
SForm_Element   $elm: 

API Tags:
Usedby:  SForm_Element::render()
Access:  public


Redefined in descendants as:

[ Top ]
applyJavaScript  [line 3007]

  string applyJavaScript( SForm $form  )

Applies the rendered JavaScript to the given form

This differs from rendJavaScript() in that this actually applies the JavaScript to the form. It sets the 'onsubmit' attribute of the form and returns an HTML/JavaScript string suitable to embed in your document.

Parameters:
object The   $form:  form to render the javascript to

API Tags:
Return:  JavaScript in HTML format
Access:  protected
Uses:  SForm_Renderer::rendJavaScript()


[ Top ]
fetch  [line 2907]

  array fetch( SForm $form  )

We need to retrieve the resulting data

This is called after the render to retrieve any useful data from it. Here, the the rendered array is returned.

Parameters:
SForm   $form: 

API Tags:
Return:  Array of values
Access:  public


Redefined in descendants as:

[ Top ]
pop  [line 2883]

  void pop( SForm_Container $node  )

Move back down in the stack

Once we move up into some container and render some elements, we must exit from said container. This is called when exiting from a container.

The passed object is the container that we are exiting out of.

Parameters:
object Current   $node:  container.

API Tags:
Access:  public


Redefined in descendants as:

[ Top ]
push  [line 2868]

  void push( SForm_Container $node  )

Move up a level in the stack

This is called when entering a contianer. That includes the base form.

The object that is passed is the container that this renderer is moving through.

Parameters:
object Current   $node:  container.

API Tags:
Access:  public


Redefined in descendants as:

[ Top ]
rendJavaScript  [line 2951]

  void rendJavaScript( string $funcName  )

Render the array of JavaScript into a script

This returns a complete JavaScript function of the requested name. This function is in a format such that it could be placed in an external document, so the user's browser can cache it. Caching would be useful if this is a large document or the user uses this form often.

This is one of the accessory methods in the renderer, it does not need to be called depending on the renderer.

If you do decide to use it, this wraps the generated JavaScript (stored in $javascript) in a function that declares the needed variables and cleans up afterward. The JavaScript function expects one parameter: the form object in the web page which is being submitted.

The "clean up" JavaScript at the end serves two purposes:

If no error was found, all of the submit buttons have their values changed to "Loading..." and become disabled. Then the form CSS is altered so the mouse cursor displays the 'wait' icon.

If an error has been thrown, an error alert is constructed and displayed. Then the first element to trigger the error is focused on to draw the user's attention to said element. All elements that are flagged also have their backgrounds yellowed.

Use the 'elmErrorColor' option to change the background color that elements are changed to. Use the 'newSubmitValue' option to disable or change how the submission buttons are changed. Use SForm_Element::setOption() to toggle these options.

Parameters:
string   $funcName:  Name of the generated function.

API Tags:
Usedby:  SForm_Renderer::applyJavaScript()
Access:  protected


[ Top ]
startForm  [line 2835]

  void startForm( SForm $form  )

Start rendering the form

By default, we really don't care if we are starting the form because our intent is just to collect the values into an array.

Parameters:
object The   $form:  form we are rendering

API Tags:
Access:  public


[ Top ]

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