tpForm Class Reference

Inherits Plugin.

Collaboration diagram for tpForm:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 tpForm ()
 propagate ($data='', $prefix='', $suffix='')
 error_box ($errors)
 tooltip ($text, $icon='')
 tooltip_bind ($elements)
 open_form ($name, $action, $method='post', $errors=array(), $attribs=array())
 close_form ()
 imagebutton ($name, $src, $attribs=array())
 submit ($name, $value='Submit', $attribs=array())
 hidden ($name, $value, $attribs=array())
 text ($name, $value='', $size='', $maxlength='', $attribs=array())
 password ($name, $value='', $size='', $maxlength='', $attribs=array())
 file ($name, $value='', $size='', $preview_url='', $remove_url='', $attribs=array())
 image ($name, $value='', $size='', $preview_url='', $remove_url='', $attribs=array())
 date ($name, $value='', $format='%Y-%m-%d', $attribs=array())
 datetime ($name, $value='', $format='%Y-%m-%d%k:%M', $attribs=array())
 color ($name, $value, $attribs=array())
 textarea ($name, $value='', $rows=10, $cols=50, $attribs=array())
 htmlarea ($name, $value='', $rows=15, $cols=100, $mceinit='', $attribs=array())
 htmlarea_preload ($mceinit='')
 checkbox ($name, $value='', $label='', $checked=false, $attribs=array())
 radio ($name, $value='', $options=array(), $sep='< br/>', $attribs=array())
 select ($name, $value='', $options=array(), $size='', $multiple=false, $attribs=array())
 _select_option ($optval, $optlbl, $value, $mult, &$sel)
 multiselect ($name, $value, $options, $show_selects=false, $multiple=true, $attribs=array())
 build_form ($params, $data=array(), $errors=array())
 build_tabbed_form ($params, $tabs, $data=array(), $errors=array())
 _show_element ($name, $elem, $attribs)
 dom_id ($name)
 _getparam ($params, $name, $default)
 _escape ($var)
 _error ($name, &$attribs)

Public Attributes

 $guid = 0
 $data_id = 0
 $errors
 $form_name
 $element_layouts

Detailed Description

PRONTO WEB FRAMEWORK Copyright © 2006, Judd Vinet

Author:
Judd Vinet <jvinet@zeroflux.org>

Description: Template plugin for common HTML elements.

Definition at line 10 of file form.php.


Member Function Documentation

tpForm::_error ( name,
&$  attribs 
)

Definition at line 1353 of file form.php.

tpForm::_escape ( var  ) 

Definition at line 1344 of file form.php.

tpForm::_getparam ( params,
name,
default 
)

Definition at line 1336 of file form.php.

References $params.

tpForm::_select_option ( optval,
optlbl,
value,
mult,
&$  sel 
)

Definition at line 707 of file form.php.

tpForm::_show_element ( name,
elem,
attribs 
)

Definition at line 1184 of file form.php.

tpForm::build_form ( params,
data = array(),
errors = array() 
)

Generate a multi-column form.

Parameters:
array $params General form parameters
array $data Values to prefill form elements with
array $errors Errors to attach to elements containing invalid data

Form Parameters:

  • form_name () :: form name
  • form_id () :: form id
  • class (form) :: CSS class to use for outer
  • action ()
  • method (POST)
  • enctype ()
  • data_id () :: PK of data element being edited
  • submit :: label on submit button; can be a 2-element array: ('create','update')
  • submit_msg :: change button message to this when clicked
  • submit_pos :: "left" or "right" (default is "right")
  • submit_html :: if set, use this for the submit button code instead of generating it
  • options array
    • noopen :: don't include opening div/form tags
    • noclose :: don't include closing div/form tags or a Submit button
    • nosubmit :: don't include a Submit button
    • nopk :: don't include the name="id" hidden element
    • toplabel :: put labels above elements instead of beside them
    • numcols :: number of columns to use for form elements (1)
    • hide_misc_errors :: don't show errors that aren't bound to an element in the form definition
    • spinner :: image to show beside submit button when clicked
  • layout array
    • <column name>=""> :: array(colspan<int>, label_width<int|"auto">, width<int>)
  • elements array
    • <name> => array
      • prompt :: label to display beside form element
      • type :: element type (see the _show_element() method for types)
      • value :: value of element
      • error :: error message associated with element
      • help :: context-specific help message
      • extra :: extra content (HTML) to be added beside the element
      • type-specific parameters (size, maxlength, rows, cols, etc)
      • attribs array :: additional html attributes

Definition at line 846 of file form.php.

References $opts, $params, __(), and assert_type().

tpForm::build_tabbed_form ( params,
tabs,
data = array(),
errors = array() 
)

Generate a tabbed form.

Parameters:
array $params General parameters
array $tabs Array of arrays containing tab labels and form definitions
array $data Values to prefill form elements with
array $errors Errors to attach to elements containing invalid data

General Parameters:

  • form_name () :: form name
  • form_id () :: form id
  • class (form) :: CSS class to use for outer
  • action ()
  • method (POST)
  • enctype ()
  • data_id () :: PK of data element being edited
  • submit :: label on submit button; can be a 2-element array: ('create','update')
  • spinner :: image to show beside submit button when clicked
Form Definitions: See build_form() $params array.
Example:

           echo $form->build_tabbed_form(
             array('data_id'=>$data['id'], 'submit'=>'Save'),
             array(
               'tab1' => array('label'=>'First Tab', 'form'=>$f1),
               'tab2' => array('label'=>'Second Tab', 'form'=>$f2, 'active'=>true),
               'tab3' => array('label'=>'Third Tab', 'content'=>'No form, just some content')
             ), $data, $errors
           );

Definition at line 1108 of file form.php.

References $opts, $params, and __().

tpForm::checkbox ( name,
value = '',
label = '',
checked = false,
attribs = array() 
)

Generate a checkbox form element

Parameters:
string $name
string $value
string $label
bool $checked
array $attribs Additional HTML attributes
Returns:
string

Definition at line 623 of file form.php.

tpForm::close_form (  ) 

Close a form. Returns the /form tag and clears any errors that were loaded for the form, returning the plugin to a clean state so a new form can be used.

Returns:
string

Definition at line 159 of file form.php.

tpForm::color ( name,
value,
attribs = array() 
)

Generate a color-selection form element

Parameters:
string $name
string $value
array $attribs Additional HTML attributes
Returns:
string

Definition at line 436 of file form.php.

tpForm::date ( name,
value = '',
format = '%Y-%m-%d',
attribs = array() 
)

Generate a date-selection form element

Parameters:
string $name
string $value
string $format Date format
array $attribs Additional HTML attributes
Returns:
string

Definition at line 362 of file form.php.

tpForm::datetime ( name,
value = '',
format = '%Y-%m-%d %k:%M',
attribs = array() 
)

Generate a date/time selection form element

Parameters:
string $name
string $value
string $format Date/time format
array $attribs Additional HTML attributes
Returns:
string

Definition at line 395 of file form.php.

tpForm::dom_id ( name  ) 

Build a DOM-friendly ID. Some characters (like underscores) are not valid and must be replaced/removed.

Parameters:
string $name The name of the element.
Returns:
string The DOM ID

Definition at line 1323 of file form.php.

tpForm::error_box ( errors  ) 

Display a list of errors in a div element

Parameters:
array $errors Associative array of errors
Returns:
string

Definition at line 84 of file form.php.

References $errors.

tpForm::file ( name,
value = '',
size = '',
preview_url = '',
remove_url = '',
attribs = array() 
)

Generate a file-upload form element

Parameters:
string $name
string $value
string $size
boolean $preview Show a "preview" link so the user can view the file currently in use.
boolean $remove Show a "remove" link so the user can delete the file currently in use without having to upload a new one.
array $attribs Additional HTML attributes
Returns:
string

Definition at line 280 of file form.php.

tpForm::hidden ( name,
value,
attribs = array() 
)

Generate a hidden form element

Parameters:
string $name
string $value
array $attribs Additional HTML attributes
Returns:
string

Definition at line 210 of file form.php.

Referenced by propagate().

tpForm::htmlarea ( name,
value = '',
rows = 15,
cols = 100,
mceinit = '',
attribs = array() 
)

Generate a rich WYSIWYG textarea form element

Parameters:
string $name
string $value
int $rows Number of rows for the textarea element
int $cols Number of columns for the textarea element
string $mceinit Initialization JS code for the MCE control; if blank, the default will be used. If an array, then the settings in the array will override those in the default. If it is a non-empty string, then that string will be used instead of the default. In this case, make sure the string is a valid Javascript object.
array $attribs Additional HTML attributes
Returns:
string

Definition at line 494 of file form.php.

tpForm::htmlarea_preload ( mceinit = ''  ) 

Preload libraries for a htmlarea widget. This function is necessary if you're going to be loading an htmlarea widget via AJAX, as TinyMCE has some pecularities when loading dynamically (eg, through a .getScript() call). To work around this, use htmlarea_preload() in the page that will be loading an htmlarea widget via AJAX.

Parameters:
array $css An array of CSS files that should be loaded into the editor widget.
string $mceinit Initialization JS code for the MCE control; if blank, the default will be used. If an array, then the settings in the array will override those in the default. If it is a non-empty string, then that string will be used instead of the default. In this case, make sure the string is a valid Javascript object.

Definition at line 607 of file form.php.

tpForm::image ( name,
value = '',
size = '',
preview_url = '',
remove_url = '',
attribs = array() 
)

Generate a file-upload form element intended for images, with a preview

Parameters:
string $name
string $value
string $size
boolean $preview Show a "preview" link so the user can view a larger version of the image currently in use.
boolean $remove Show a "remove" link so the user can delete the image currently in use without having to upload a new one.
array $attribs Additional HTML attributes
Returns:
string

Definition at line 322 of file form.php.

tpForm::imagebutton ( name,
src,
attribs = array() 
)

Generate an image input tag

Parameters:
string $name Name attribute
string $src URL of image
array $attribs Additional HTML attributes
Returns:
string

Definition at line 173 of file form.php.

tpForm::multiselect ( name,
value,
options,
show_selects = false,
multiple = true,
attribs = array() 
)

Generate a multi-select form element that is more intuitive than the standard select with CTRL-click. Can also be used for single selects.

Parameters:
string $name
mixed $value The current selection(s)
array $options A hash of option=>value tuples
boolean $show_selects Show select-all and select-none icons
boolean $multiple Allow multiple selections
array $attribs Additional HTML attributes
Returns:
string

Definition at line 736 of file form.php.

References __().

tpForm::open_form ( name,
action,
method = 'post',
errors = array(),
attribs = array() 
)

Open a new form. Returns the form tag, and can optionally load in an array of errors that can be linked to form elements within this form.

Parameters:
string $name Name and ID of the form element
string $method Submission method ('get' or 'post')
array $errors Associative array of errors
array $attribs Additional HTML attributes
Returns:
string

Definition at line 139 of file form.php.

tpForm::password ( name,
value = '',
size = '',
maxlength = '',
attribs = array() 
)

Generate a password form element

Parameters:
string $name
string $value
string $size
string $maxlength
array $attribs Additional HTML attributes
Returns:
string

Definition at line 253 of file form.php.

tpForm::propagate ( data = '',
prefix = '',
suffix = '' 
)

Propagate all GET/POST fields into hidden form elements

Parameters:
mixed $data If blank, propagate all GET/POST vars. If set to "get" or "post", propagate only those variables. If set to an array, propagate all values in the array.
Returns:
string

Definition at line 54 of file form.php.

References hidden().

tpForm::radio ( name,
value = '',
options = array(),
sep = '<br />',
attribs = array() 
)

Generate a radio form element

Parameters:
string $name
string $value
array $options
string $sep Separator to use between options (default is a BR tag)
array $attribs Additional HTML attributes
Returns:
string

Definition at line 645 of file form.php.

tpForm::select ( name,
value = '',
options = array(),
size = '',
multiple = false,
attribs = array() 
)

Generate a select/dropdown form element

Parameters:
string $name
string $value
array $options
int $size
bool $multiple
array $attribs Additional HTML attributes
Returns:
string

Definition at line 677 of file form.php.

tpForm::submit ( name,
value = 'Submit',
attribs = array() 
)

Generate a submit button

Parameters:
string $name Name attribute
string $value Button text
array $attribs Additional HTML attributes
Returns:
string

Definition at line 192 of file form.php.

tpForm::text ( name,
value = '',
size = '',
maxlength = '',
attribs = array() 
)

Generate a text form element

Parameters:
string $name
string $value
string $size
string $maxlength
array $attribs Additional HTML attributes
Returns:
string

Definition at line 230 of file form.php.

tpForm::textarea ( name,
value = '',
rows = 10,
cols = 50,
attribs = array() 
)

Generate a textarea form element

Parameters:
string $name
string $value
int $rows
int $cols
array $attribs Additional HTML attributes
Returns:
string

Definition at line 466 of file form.php.

tpForm::tooltip ( text,
icon = '' 
)

Generate a tooltip (contextual help) icon. When the mouse hovers over it, a little popup will appear, displaying the help text.

Parameters:
string $text The text to display in the popup.
string $icon URL of the icon to use, relative to the /img directory. Default is icons/info.gif.
Returns:
string The resulting HTML.

Definition at line 103 of file form.php.

Referenced by tooltip_bind().

tpForm::tooltip_bind ( elements  ) 

Bind tooltip functionality to one or more elements. The value of the element's "title" attribute will be used for the tooltip content.

Parameters:
string $dom_id The jQuery selector of the elements.

Definition at line 121 of file form.php.

References tooltip().

tpForm::tpForm (  ) 

Constructor

Definition at line 22 of file form.php.

References Plugin_Base::depend(), and Plugin::Plugin().


Member Data Documentation

tpForm::$data_id = 0

Definition at line 13 of file form.php.

tpForm::$element_layouts

Definition at line 17 of file form.php.

tpForm::$errors

Definition at line 15 of file form.php.

Referenced by error_box().

tpForm::$form_name

Definition at line 16 of file form.php.

tpForm::$guid = 0

Definition at line 12 of file form.php.


The documentation for this class was generated from the following file:

Generated on Wed Jan 13 09:21:05 2010 for Pronto Framework by  doxygen 1.6.1