Pluf_Form Class Reference

Inheritance diagram for Pluf_Form:

Pluf_Form_Model

List of all members.

Public Member Functions

 __construct ($data=null, $extra=array(), $label_suffix=null)
 initFields ($extra=array())
 addPrefix ($field_name)
 isValid ()
 clean ()
 failed ()
 initial ($name)
 render_top_errors ()
 get_top_errors ()
 render_p ()
 render_ul ()
 render_table ()
 __get ($prop)
 field ($key)
 current ()
 key ()
 next ()
 rewind ()
 valid ()
 offsetUnset ($index)
 offsetSet ($index, $value)
 offsetGet ($index)
 offsetExists ($index)

Public Attributes

 $fields = array()
 $prefix = ''
 $id_fields = 'id_%s'
 $data = array()
 $cleaned_data = array()
 $errors = array()
 $is_bound = false
 $f = null
 $label_suffix = ':'

Protected Member Functions

 htmlOutput ($normal_row, $error_row, $row_ender, $help_text_html, $errors_on_separate_row)

Protected Attributes

 $is_valid = null


Detailed Description

Form validation class.

This class is used to generate a form. You basically build it the same way you build a model.

The form handling is heavily inspired by the Django form handling.


Constructor & Destructor Documentation

Pluf_Form::__construct ( data = null,
extra = array(),
label_suffix = null 
)


Member Function Documentation

Pluf_Form::initFields ( extra = array()  ) 

Reimplemented in Pluf_Form_Model.

Pluf_Form::addPrefix ( field_name  ) 

Add the prefix to the form names.

Parameters:
string Field name.
Returns:
string Field name or field name with form prefix.

Pluf_Form::isValid (  ) 

Check if the form is valid.

It is also encoding the data in the form to be then saved. It is very simple as it leaves the work to the field. It means that you can easily extend this form class to have a more complex validation procedure like checking if a field is equals to another in the form (like for password confirmation) etc.

Parameters:
array Associative array of the request
Returns:
array Array of errors

Pluf_Form::clean (  ) 

Form wide cleaning function. That way you can check that if an input is given, then another one somewhere is also given, etc. If the cleaning is not ok, your method must throw a Pluf_Form_Invalid exception.

Returns:
array Cleaned data.

Pluf_Form::failed (  ) 

Method just called after the validation if the validation failed. This can be used to remove uploaded files. $this->['cleaned_data'] will be available but of course not fully populated and with possible garbage due to the error.

Pluf_Form::initial ( name  ) 

Get initial data for a given field.

Parameters:
string Field name.
Returns:
string Initial data or '' of not defined.

Pluf_Form::render_top_errors (  ) 

Get the top errors.

Pluf_Form::get_top_errors (  ) 

Get the top errors.

Pluf_Form::htmlOutput ( normal_row,
error_row,
row_ender,
help_text_html,
errors_on_separate_row 
) [protected]

Helper function to render the form.

See render_p() for a usage example.

Django Project (http://www.djangoproject.com/)

Parameters:
string Normal row.
string Error row.
string Row ender.
string Help text HTML.
bool Should we display errors on a separate row.
Returns:
string HTML of the form.

Pluf_Form::render_p (  ) 

Render the form as a list of paragraphs.

Pluf_Form::render_ul (  ) 

Render the form as a list without the

Pluf_Form::render_table (  ) 

Render the form as a table without
.

Pluf_Form::__get ( prop  ) 

Overloading of the get method.

The overloading is to be able to use property call in the templates.

Pluf_Form::field ( key  ) 

Get a given field by key.

Pluf_Form::current (  ) 

Iterator method to iterate over the fields.

Get the current item.

Pluf_Form::key (  ) 

Pluf_Form::next (  ) 

Pluf_Form::rewind (  ) 

Pluf_Form::valid (  ) 

Pluf_Form::offsetUnset ( index  ) 

Pluf_Form::offsetSet ( index,
value 
)

Pluf_Form::offsetGet ( index  ) 

Pluf_Form::offsetExists ( index  ) 


Member Data Documentation

Pluf_Form::$fields = array()

The fields of the form.

They are the fully populated Pluf_Form_Field_* of the form. You define them in the initFields method.

Pluf_Form::$prefix = ''

Prefix for the names of the fields.

Pluf_Form::$id_fields = 'id_%s'

Pluf_Form::$data = array()

Pluf_Form::$cleaned_data = array()

Pluf_Form::$errors = array()

Pluf_Form::$is_bound = false

Pluf_Form::$f = null

Pluf_Form::$label_suffix = ':'

Pluf_Form::$is_valid = null [protected]


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

Generated on Wed Feb 3 15:44:52 2010 for Pluf by  doxygen