PHP的表单类 Zebra_Form &Form Builder PHP Class

Zebra_Form 是一个 PHP 类用于简化表单的创建和数据验证。示例代码:
01<?php
02// include the Zebra_Form class
03require 'path/to/Zebra_Form.php';
04 
05// instantiate a Zebra_Form object
06$form = new Zebra_Form('form');
07 
08// the label for the "email" field
09$form->add('label','label_email', 'email', 'Email');
10 
11// add the "email" field
12// the "&" symbol is there so that $obj will be a reference to the object in PHP 4
13// for PHP 5+ there is no need for it
14$obj = & $form->add('text','email', '',array('autocomplete'=> 'off'));
15 
16// set rules
17$obj->set_rule(array(
18// error messages will be sent to a variable called "error", usable in custom templates
19'required'=> array('error','Email is required!'),
20'email'=> array('error','Email address seems to be invalid!'),
21));
22 
23// "password"
24$form->add('label','label_password', 'password', 'Password');
25$obj = & $form->add('password','password', '', array('autocomplete'=> 'off'));
26$obj->set_rule(array(
27'required'=> array('error','Password is required!'),
28'length'=> array(6, 10,'error', 'The password must have between 6 and 10 characters'),
29));
30 
31// "remember me"
32$form->add('checkbox','remember_me', 'yes');
33$form->add('label','label_remember_me_yes','remember_me_yes','Remember me');
34 
35// "submit"
36$form->add('submit','btnsubmit', 'Submit');
37 
38// validate the form
39if ($form->validate()) {
40// do stuff here
41}
42// auto generate output, labels above form elements
43$form->render();
44?>
项目地址:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值