Documenation

Form

/_plugins/form.php

This is a plug-in to validate input send through HTML forms (POST data).

Example

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
$model
->form->validate(array(
    
'submit' => 'bool',
    
'name'   => 'string, empty'
    'email'  
=> 'email'
    
));

if ( 
$model->POST_valid['submit'] )
{
    if ( 
$model->form->errors )
    {
        if ( 
$model->form->errors['email'] )
        {
            
$view->error 'Please provide a valid e-mail address.';
        }
    }
    else
    {
        
// Process form
    
}
}
?>

List of possible validation types

  • bool
    TRUE (any value) or FALSE (no value or 0 (zero)), mainly used for submit buttons and checkboxes.
  • email
    Valid e-mail address.
  • empty
    No value.
  • int
    Integer (positive or negative), no longer then 256 characters.
  • string
    Any text, no longer then 256 characters. Longer text usually doesn't require validation (all characters allowed).
  • Custom
    It's possible to create a custom validation type using a regular expression (e.g. /^[a-z]{2}$/i).

Multiple types can be used at once by separating them with a comma.

Class

$model->form

Public functions

  • $model->form->validate ( array $vars )

Public variables

  • $model->form->errors
    Array containing all fields that failed validation ($model->form->errors[$k] = TRUE).

See also