Zebra_Form 是一个 PHP 类用于简化表单的创建和数据验证。其面向对象的结构促进快速发展的HTML形式,并鼓励开发者编写清洁和易于维护的代码。它摆脱了书面形式的验证码重复任务,提供强大的发展客户端和服务器端验证。 Zebra_Form集成了一个跨站点脚本的防范机制,可自动带出从提交的数据潜在的恶意代码。它还可以防止垃圾邮件的自动投递,不依赖CAPTCHA的使用。
输出可自动或手动生成通过模板(基本PHP文件)。当自动生成,生成的输出验证为HTML 4.01 Strict或XHTML1.0 Strict并具有相同的外观和跨平台如Firefox,Chrome,Opera,Safari和Internet Explorer的所有主要浏览器。它提供了所有的控制在一个HTML表单,以及日期/时间的选择,CAPTCHA和AJAX文件上传控件。客户端验证是基于MooTools的JavaScript框架(以及它的工作原理与MooTools 1.2.5和MooTools 1.3或不兼容模式)。该代码是注释并不会产生警告/错误/通知在PHP的错误报告级别设置为E_ALL。
Zebra_Form 2.6.1一个错误的客户端验证的设置将被重置,如果一个文件上传控件添加到窗体。修正一个客户端验证会崩溃的错误,一天的日期格式中名称或月份的名称可定制。修正一个如果脚本中的日期格式“/”(斜线)崩溃的错误等等。
示例:
The HTML
<!-- must be in strict mode! --><!DOCTYPE html><html> <head> <title>Zebra_Form Example</title> <meta charset="utf-8"> <!-- load Zebra_Form's stylesheet file --> <link rel="stylesheet" href="path/to/zebra_form.css"> <!-- load jQuery --> <script src="path/to/jquery.js"></script> <!-- load Zebra_Form's JavaScript file --> <script src="path/to/zebra_form.js"></script> </head> <body> <!-- the PHP code below goes here --> </body></html>
The PHP
<?php// include the Zebra_Form classrequire '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 formif ($form->validate()) { // do stuff here}// auto generate output, labels above form elements$form->render();?>
下载地址:http://stefangabos.ro/wp-content/uploads/php-libraries/zebra_form.2.6.1.zip