classname: htmlobject_formbuilder


extends: htmlobject_form

 Formbuilder

@package htmlobjects
@author Alexander Kuballa [akuballa@users.sourceforge.net]
@copyright Copyright (c) 2008 - 2010, Alexander Kuballa
@license BSD License (see LICENSE.TXT)
@version 1.0

filename: htmlobject.formbuilder.class.php

Attributes

top
attribute: box_css
access: public
default:
htmlobject_box

Css class for boxes

@access public
@var string
top
attribute: display_errors
access: public
default:
true

Display errors inline

@access public
@var bool
top
attribute: request_filter
access: public
default:
array(
		array( 'pattern' => '~\r\n~', 'replace' => "\n"),
		array( 'pattern' => '~&#60

Request filter for form elements

@access public
@var array

$form = new htmlobject_formbuilder($htmlobject);
$form->request_filter = array(
   array ( 'pattern' => '~\r\n~', 'replace' => '\n'),
 );
# disable filter
$form->request_filter = array();
top
attribute: value_filter
access: public
default:
array(
		array( 'pattern' => '&', 'replace' => '&#38

Value filter for form elements

uses str_replace

@access public
@var array

$form = new htmlobject_formbuilder($htmlobject);
$form->value_filter = array(
   array ( 'pattern' => '<', 'replace' => '&#60;'),
 );
# disable filter
$form->value_filter = array();


Methods

top
function: __construct
params:
$htmlobject

 Constructor
 
 @access public
 @param htmlobject $htmlobject
top
function: init

 Init Formbuilder
 
 @access public
top
function: add
params:
$data
$key = null

 Add additional content
 
 @access public
 @param array $data
 @param dummy $key set for compatibility
  
 $html = new htmlobject('path_to_htmlobjects');
 
 $data['name']['label']                     = 'Name';
 $data['name']['required']                  = true;
 // static
 // element will not be returned by get_request()
 // if false element will trigger submited
 // if true element will be ignored
 $data['name']['static']                    = false;
 // validation
 $data['name']['validate']['regex']         = '/^[a-z0-9~._-]+$/i';
 $data['name']['validate']['errormsg']      = 'string must be a-z0-9~._-';
 // build object
 $data['name']['object']['type']            = 'htmlobject_input';
 $data['name']['object']['attrib']['type']  = 'text';
 $data['name']['object']['attrib']['name']  = 'name';
 $data['name']['object']['attrib']['value'] = 'somevalue';
 
 $formbuilder = $html->formbuilder();
 $formbuilder->add( $data );
 
 // Actions
 // no errors, do something
 if(!$formbuilder->get_errors()) {
    $values = $formbuilder->get_request();
    print_r($values);
 }
 
top
function: get_elements
params:
$name = null

 Get array of objects
 
 will return array($name => htmlobject_box)
 
 @access public
 @param string $name name of element
 @return array of objects
top
function: get_object

 Get form objects
 
 @access public
 @return htmlobject_form
top
function: get_string

 Get formbuilder as string
 
 @access public
 @return string
top
function: get_request
params:
$name = null

 Get request values as array
     
 @access public
 @param string $name name of input
 @return array|string
top
function: get_errors
params:
$name = null

 Get one or all errors
 
 return array('name' => 'errormsg', ...)
 or string 'errormsg' if param name is set
 or null if no error occured
 
 @access public
 @param string $name key of element
 @return string|array|null
top
function: get_static
params:
$name = null

 Get one or all static
 
 @access public
 @param string $name key of element
 @return string|array|null
top
function: set_error
params:
$name
$value

 Set error by element name
 
 @access public
 @param string $name name of input
 @param string $value
top
function: set_label
params:
$key
$value

 Set label
 
 @access public
 @param string $key key of element
 @param string $value
top
function: remove
params:
$name

 Remove element by name
 
 @access public
 @param string $name name of input
top
function: __set_request

 Set values from http request as array
 
 @access protected
top
function: __set_request_errors

 Check $this->__data request
 
 Returns array of errors if
 request does not match given regex.
 Empty if no missmatch occured.
 
 @access protected
 @todo pregmatch for arrays
top
function: __set_elements_value

 Set elements value
 make sure data, request and request_errors
 are set first
 
 @access protected
top
function: __handle_htmlobject
params:
$key
$value

 Handle htmlobject
 
 @access protected
 @param string $key
 @param string $value
top
function: __get_label
params:
$key

 Handle label
 
 @access protected
 @param string $key
 @return string