Zebra_Form 2.8 发布,PHP表单处理类

发布于 2012年03月14日
收藏 2

Zebra_Form 2.8 发布了,该版本修复了一个 bug ,该 bug 导致 attach_tip() 的 JavaScript 方法无法正常运行,因为 JavaScript 和 PHP 对待新行的处理方式不同导致。

Zebra_Form 是一个 PHP 类用于简化表单的创建和数据验证。


// include the Zebra_Form class
require 'path/to/Zebra_Form.php';

// instantiate a Zebra_Form object
$form = new Zebra_Form('form');

// the label for the "email" field
$form->add('label', 'label_email', 'email', 'Email');

// add the "email" field
// the "&" symbol is there so that $obj will be a reference to the object in PHP 4
// for PHP 5+ there is no need for it
$obj = & $form->add('text', 'email', '', array('autocomplete' => 'off'));

// set rules
    // error messages will be sent to a variable called "error", usable in custom templates
    'required'  =>  array('error', 'Email is required!'),
    'email'     =>  array('error', 'Email address seems to be invalid!'),

// "password"
$form->add('label', 'label_password', 'password', 'Password');
$obj = & $form->add('password', 'password', '', array('autocomplete' => 'off'));
    'required'  => array('error', 'Password is required!'),
    'length'    => array(6, 10, 'error', 'The password must have between 6 and 10 characters'),

// "remember me"
$form->add('checkbox', 'remember_me', 'yes');
$form->add('label', 'label_remember_me_yes', 'remember_me_yes', 'Remember me');

// "submit"
$form->add('submit', 'btnsubmit', 'Submit');

// validate the form
if ($form->validate()) {
    // do stuff here
// auto generate output, labels above form elements
转载请注明:文章转载自 开源中国社区 [http://www.oschina.net]
本文标题:Zebra_Form 2.8 发布,PHP表单处理类