Zebra_Form是一个用于简化表单的创建和数据验证的PHP类。
Zebra_Form 2.2修复了自定义表单验证的bug,修复了日期控件的验证bug以及PHP5生成输出信息的bug等。
Zebra_Form 2.2发行说明:
fixed a bug where, for custom validations, the ">JavaScript function was not getting any additional arguments except the element’s value (thanks to Robert Grzesinski for reporting) fixed a bug where the “date” control would add an invalid attribute to the element that would cause the generated output not to pass the W3C validation fixed a bug where in the newest versions of PHP 5 the script would generate “PHP Strict Standards” notices because of how mktime() (with no arguments) and
array_shift() is treated in these versions some documentation updates and clarifications (thanks to Andrei Bodeianschi for suggesting some of those)
使用示例:
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.2.zip