pclib  3.0.0
Lightweight PHP framework
PClib callback functions

You can override default element print/validate handler for any element (tag) in template. PClib supports two events when your handlers can be called:

  • when element is printed into template
  • when element is validated (only in form)

You must set your handler in elements section of the template, like this:

string NAME onprint "printName"

or

input NAME onvalidate "validateName"

for validation.

Next, you must define your handler in php source code. Note that handler can be any php callable.

function printName($sender, $id, $sub, $value) {...}

  • $sender is reference to calling template object
  • $id is ID of the element
  • $sub is tag modificator
  • $value is current value of the element

With print handler you can modify result printed into template, or perform some additional actions. Example:

function printName($sender, $id, $sub, $value)
{
print "Your name is <b>$value</b>";
}
function validateName($sender, $id, $sub, $value)
{
if (!in_array($value, array('Steve','Bill','Linus')))
return "This name is not allowed!"
else
return '';
}

Since php 5.3.0 you can use even anonymous functions as handler:

$form->_NAME->onprint = function($sender, $id, $sub, $value) {...}