PHP程序员站--PHP编程开发平台
 当前位置:主页 >> 新闻咨询 >> 业内新闻 >> 

Zebra_Form 2.2 发布,PHP的表单类

Zebra_Form 2.2 发布,PHP的表单类

来源:PHP程序员站  作者:PHP程序员站  发布时间:2011-06-12
该版本修复了自定义表单验证的bug,修复了日期控件的验证bug 以及 PHP5 生成输出信息的bug等。 Zebra_Form 是一个 PHP 类用于简化表单的创建和数据验证。 示例代码: ?php // include the Zebra_Form class require 'path/to/Zebra_Form.php'; // instantiate a Zebra_

该版本修复了自定义表单验证的bug,修复了日期控件的验证bug 以及 PHP5 生成输出信息的bug等。


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

示例代码:

<?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
$obj->set_rule(array(
    // 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'));
$obj->set_rule(array(
    '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
$form->render();
?>

Tags: Zebra_Form   php   表单类  
最新文章
推荐阅读
月点击排行榜
PHP程序员站 Copyright © 2007-2010,PHPERZ.COM All Rights Reserved 粤ICP备07503606号