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

Class: pnFormPlugin

Source Location: /includes/pnForm.php

Class Overview


Base plugin class


Variables

Methods


Child classes:

pnFormStyledPlugin
Base plugin class for plugins that uses CSS styling
pnFormTabbedPanel
Tabbel panel element
pnFormTabbedPanelSet
Tabbed panel set
pnFormVolatile
Volatile block container
pnFormContextMenuItem
Context menu item
pnFormContextMenuReference
Context menu reference
pnFormContextMenuSeparator
Context menu separator
pnFormErrorMessage
Error message placeholder
pnFormPostBackFunction
PostBack JavaScript function plugin
pnFormValidationSummary
Validation summary

Class Details

[line 1203]
Base plugin class

This is the base class to inherit from when creating new plugins for the pnForm framework. Every pnForm plugin is normally created in a Smarty plugin function file and registered in the pnForm framewith with the use of pnFormRender::pnFormRegisterPlugin().

Member variables in a plugin object is persisted accross different page requests. This means a member variable $this->X can be set on one request and on the next request it will still contain the same value. This probably removes 99% of the use of hidden HTML variables in your web forms. A member variable must be declared in order to be persisted:

  1.  class MyPlugin inherits pnFormPlugin
  2.  {
  3.     var $X;
  4.  }

Member variables in a plugin will be assigned automatically from Smarty parameters when the variable and parameter names match. So assume you have a plugin like this:

  1.  class MyPlugin inherits pnFormPlugin
  2.  {
  3.     var $X;
  4.  }

Then X will be set to 1234 through this template declaration:

  1.  <!--[MyPlugin X="1234"]-->

A registered plugin will be notified of various events that happens during it's life-cycle. When a specific event occurs then the corresponding event handler (class method) will be executed. Handlers are named exactly like their events - this is how the framework knows which methods to call.

The list of events is:

  • create: Similar to a constructor since it is called directly after the plugin has been created. In this event handler you should set the various member variables your plugin requires. You can access Smarty parameters through the $params object. The automatic setting of member variables from Smarty parameters happens after the create event. This event is only fired the first time the plugin is instantiated, but not when restored from saved state.
  • load: Called immediately after member variables has been set from their Smarty parameters. So the plugin is assumed to be fully initialized when the load event is fired. During the load event the plugin is expected to load values from the render object.
A typical load event handler will just call the loadValue handler and pass it the values of the render object (to improve reuse). The loadValue method will then take care of the rest. This is also the place where validators should be added to the list of validators. Example:
  1.    function load(&$render&$params)
  2.    {
  3.      $this->loadValue($render$render->get_template_vars());
  4.      $render->pnFormAddValidator($this);
  5.    }
This event is only fired the first time the plugin is instantiated, but not when restored from saved state.

  • initialize: this event is the opposite of the create/load event pair. It fires when a plugin has been restored from a postback (and before then decode event).
  • decode: this event is fired on postback in order to let the plugin decode the HTTP POST values sent by the browser. It is left to the plugin to decide where to store the decode data.
  • dataBound: this event is fired when plugin is loaded and ready - both on postback and the initial page display.
  • render: this event is fired when the plugin is required to render itself based on the data it got through the previous events. This function is only called on Smarty function plugins. The event handler is supposed to return the rendered output.
  • renderBegin: this event is for Smarty block plugins only. It is fired in order to allow the plugin to render something before the plugins contained within it.
  • renderContent: this event is for Smarty block plugins only. It is fired in order to allow the plugin to modify content renderes by the plugins contained within it.
  • renderEnd: this event is for Smarty block plugins only. It is fired in order to allow the plugin to render something after the plugins contained within it.
  • postRender: this event is fired after all rendering is done for all plugins on the page. In this event handler you can use pnFormRender::pnFormGetPluginById() to fetch other plugins and read/modify their data.
Most events on one plugin happens before the next plugin is loaded (except the postRender event). So for two plugins A and B you would get the event sequence (assuming B is placed after A in the Smarty template):
  • A::create
  • A::load
  • ...
  • A:render
  • B::create
  • B::load
  • ...
  • B:render
  • A::postRender
  • B::postRender




[ Top ]


Class Variables

$attributes =

[line 1240]

HTML attributes

Associative array of attributes to add to the plugin. For instance: array('title' => 'A tooltip title', onclick => 'doSomething()')



Type:   array


[ Top ]

$blockBeginOutput =

[line 1288]

Temporary storage of the output from renderBegin in blocks


Type:   mixed


[ Top ]

$id =

[line 1216]

Plugin identifier

This contains the identifier for the plugin. You can use this ID in pnFormRender::pnFormGetPluginById() as well as in JavaScript where it should be set on the HTML elements (this does although depend on the plugin implementation).

Do not change this variable!



Type:   string


[ Top ]

$onDataBound =

[line 1273]

Name of function to call in form event handler when plugin is loaded

If you need to notify the form event handler when the plugin has been loaded then specify the name of this handler here. The prototype of the function must be: function MyOnLoadHandler(&$render, &$plugin, $params) where $render is the form render, $plugin is this plugin, and $params are the Smarty parameters passed to the plugin.

The data bound handler is called both on postback and first page render.

Example:

  1.  class MyPlugin extends pnFormPlugin
  2.  {
  3.    function MyPlugin()
  4.    {
  5.       $this->onDataBound 'MyLoadHandler';
  6.    }
  7.  }
  8.  
  9.  class MyFormHandler extends pnFormHandler
  10.  {
  11.    function MyLoadHandler(&$render&$plugin$params)
  12.    {
  13.      // Do stuff here
  14.    }
  15.  }

The name "dataBound" was chosen to avoid clashes with the "load" event.



Type:   mixed


[ Top ]

$parentPlugin =

[line 1230]

Reference to parent plugin if used inside a block


Type:   &pnFormHandler


[ Top ]

$plugins =

[line 1282]

Reference to sub-plugins

This variable contains an array of references to sub-plugins when this plugin is a block plugin containing other plugins.



Type:   array


[ Top ]

$visible =

[line 1223]

Specifies whether or not a plugin should be rendered


Type:   bool


[ Top ]

$volatile =

[line 1295]

Volatile indicator (disables state management in sub-plugins)


Type:   bool


[ Top ]



Class Methods


constructor pnFormPlugin [line 1301]

pnFormPlugin pnFormPlugin( &$render, &$params)

Constructor



Parameters:

   &$render  
   &$params  

[ Top ]

method create [line 1342]


method dataBound [line 1416]

void dataBound( pnFormRender &$render, array &$params)

DataBound event handler

Default action is to call onDataBound handler in form event handler.




Tags:

see:  pnFormPlugin


Overridden in child classes as:

pnFormContextMenu::dataBound()

Parameters:

pnFormRender   &$render   Reference to pnForm render object
array   &$params   Parameters passed from the Smarty plugin function

[ Top ]

method decode [line 1386]

void decode( pnFormRender &$render, array &$params)

Decode event handler

Default action is to do nothing




Tags:

see:  pnFormPlugin


Overridden in child classes as:

pnFormCheckbox::decode()
pnFormRadioButton::decode()
pnFormTextInput::decode()
pnFormUploadInput::decode()
pnFormCheckboxList::decode()
pnFormDropdownList::decode()
pnFormTabbedPanelSet::decode()

Parameters:

pnFormRender   &$render   Reference to pnForm render object
array   &$params   Parameters passed from the Smarty plugin function

[ Top ]

method decodePostBackEvent [line 1401]

void decodePostBackEvent( pnFormRender &$render, array &$params)

Decode event handler for actions that generate a postback event

Default action is to do nothing. Usefull for buttons that should generate events after the plugins have decoded their normal values.




Overridden in child classes as:

pnFormButton::decodePostBackEvent()
pnFormImageButton::decodePostBackEvent()

Parameters:

pnFormRender   &$render   Reference to pnForm render object
array   &$params   Parameters passed from the Smarty plugin function

[ Top ]

method getIdHtml [line 1530]

string getIdHtml( [ $id = null])

Utility function to generate HTML for ID attribute

Generate id="..." for use in the plugin's render methods.

This function ignores automatically created IDs (those named "plgNNN") and will return an empty string for these.




Parameters:

   $id  

[ Top ]

method initialize [line 1371]

void initialize( pnFormRender &$render)

Initialize event handler

Default action is to do nothing. Typically used to add self as validator.




Tags:

see:  pnFormPlugin


Overridden in child classes as:

pnFormRadioButton::initialize()
pnFormTextInput::initialize()
pnFormUploadInput::initialize()
pnFormBaseListSelector::initialize()

Parameters:

pnFormRender   &$render   Reference to pnForm render object

[ Top ]

method load [line 1357]

void load( pnFormRender &$render, array &$params)

Load event handler

Default action is to do nothing.




Tags:

see:  pnFormPlugin


Overridden in child classes as:

pnFormCheckbox::load()
pnFormRadioButton::load()
pnFormTextInput::load()
pnFormBaseListSelector::load()
pnFormCheckboxList::load()
pnFormCategoryCheckboxList::load()
pnFormDropdownList::load()
pnFormCategorySelector::load()
pnFormLanguageSelector::load()

Parameters:

pnFormRender   &$render   Reference to pnForm render object
array   &$params   Parameters passed from the Smarty plugin function

[ Top ]

method postRender [line 1509]

void postRender( pnFormRender &$render)

PostRender event handler

Default action is to do nothing.




Tags:

see:  pnFormPlugin


Overridden in child classes as:

pnFormLabel::postRender()

Parameters:

pnFormRender   &$render   Reference to pnForm render object

[ Top ]

method readParameters [line 1317]

void readParameters( &$render, &$params)

Read Smarty plugin parameters

This is the function that takes care of reading smarty parameters and storing them in the member variables or attributes (all unknown parameters go into the "attribues" array). You can override this for special situations.




Parameters:

   &$render  
   &$params  

[ Top ]

method registerPlugin [line 1514]

void registerPlugin( &$render, &$plugin)



Parameters:

   &$render  
   &$plugin  

[ Top ]

method render [line 1448]


method renderAttributes [line 1426]

void renderAttributes( &$render)



Overridden in child classes as:

pnFormStyledPlugin::renderAttributes()

Parameters:

   &$render  

[ Top ]

method renderBegin [line 1463]

string renderBegin( pnFormRender &$render)

RenderBegin event handler

Default action is to return an empty string.




Tags:

return:  The rendered output
see:  pnFormPlugin


Overridden in child classes as:

pnFormContextMenu::renderBegin()
pnFormTabbedPanel::renderBegin()

Parameters:

pnFormRender   &$render   Reference to pnForm render object

[ Top ]

method renderContent [line 1479]

string renderContent( pnFormRender &$render, $content)

RenderContent event handler

Default action is to return the content unmodified.




Tags:

return:  The (optionally) modified content
see:  pnFormPlugin


Overridden in child classes as:

pnFormTabbedPanelSet::renderContent()

Parameters:

pnFormRender   &$render   Reference to pnForm render object
   $content  

[ Top ]

method renderEnd [line 1494]

string renderEnd( pnFormRender &$render)

RenderEnd event handler

Default action is to return an empty string.




Tags:

return:  The rendered output
see:  pnFormPlugin


Overridden in child classes as:

pnFormContextMenu::renderEnd()
pnFormTabbedPanel::renderEnd()

Parameters:

pnFormRender   &$render   Reference to pnForm render object

[ Top ]


Documentation generated on Fri, 18 Jul 2008 21:52:55 +0200 by phpDocumentor 1.4.1