首頁  >  文章  >  後端開發  >  Zebra_Form PHP表单验证类

Zebra_Form PHP表单验证类

WBOY
WBOY原創
2016-06-20 13:04:471222瀏覽

Zebra_Form构建兼容所有浏览器,具有客户端+服务器校验功能并且外观漂亮的HTML表单,将会发费比较的开发时间。Zebra_Form是一个能够很好处理这些过程,利用它只需要几行代码就能够帮忙我们构建一个安全、优美的表单。输出的结果可以自定义外观,也可以自定义。

功能特点

1、提供保护,防止跨站点脚本(XSS)以及跨站点请求伪造(CSRF)攻击。
2、它会自动阻止使用“灌水”技术(CAPTCHA系统,也可用于更强大的保护)进行的表单提交
3、同时提供服务器端和客户端验证(客户端验证是通过使用jQuery的1.5.2+);可以很容易地添加自定义的验证规则(包括基于AJAX)
4、使用模板形式的“布局可以自动或手动生成“
5、输出html代码经过HTML4.01、XHTML 1.0或HTML5严格验证
6、适用于所有的主流浏览器如Firefox,Chrome浏览器,Safari浏览器和Internet Explorer6+

如何使用

The HTML





Zebra_Form Example











The 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
$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();
?>

项目地址:http://stefangabos.ro/php-libraries/zebra-form/


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn