>php教程 >php手册 >PHP PEAR/HTML/QuickForm实现用户注册表单界面

PHP PEAR/HTML/QuickForm实现用户注册表单界面

WBOY
WBOY원래의
2016-06-21 08:59:421148검색

  用PEAR中的QuickForm实现了一个用户注册的界面,具体的操作数据库没有写。可能是我还不太熟练吧,没发现它的优点,反而不如JS,HTML直接编写来得迅速。也许它的好处就是可以控制很多吧(不是指外观)。下面的例子就实现了用户名,EMAIL地址的格式检查,证件号码等等的检查,当然这些用JS都可以轻松完成的,大家见仁见智吧。下面是最终效果图:

下面是PHP代码
  /**
   * QuickForm手工篇
   *
   * QuickForm手工输入之熟练篇
   * 用QuickForm完成一个用户注册页面(包括信息的审查功能)
   * @author jxyuhua at gmail.com
   */
   require_once("HTML/QuickForm.php");
   echo("");
   $quickForm = new HTML_QuickForm("registerFrm");
   $country  = array("1" => "中国",
                    "2" => "日本",
                    "3" => "美国",
                    "4" => "英国",
                    "0" => "其它");
   $city     = array("1" => "北京",
                    "2" => "广东",
                    "3" => "江西",
                    "0" => "其它");
   $industry = array("1" => "学生",
                    "2" => "科研机构",
                    "3" => "IT产业",
                    "0" => "其它");
   $from     = array("1" => "网吧",
                    "2" => "单位",
                    "3" => "家里",
                    "0" => "其它");
   $quickForm->setDefaults(array("idtype" => 1,
                                 "secret" => 1));
   $quickForm->addElement("header", null, "新用户注册");
   $quickForm->addElement("text", "name", "用户登录呢称:", array("size" => 20, "maxlength" => 20));
   $quickForm->addElement("password", "pass", "密码:", array("size" => 20, "maxlength" => 20));
   $quickForm->addElement("password", "repass", "重复输入密码:", array("size" => 20, "maxlength" => 20));
   $quickForm->addElement("text", "email", "EMAIL地址:", array("size" => 20, "maxlength" => 50));
   $quickForm->addElement("text", "passquestion", "密码提示问题:", array("size" => 50, "maxlength" => 50));
   $quickForm->addElement("text", "passanswer", "密码提示答案:", array("size" => 50, "maxlength" => 50));
   $quickForm->addElement("text", "alias", "用户中文呢称:", array("size" => 30, "maxlength" => 50));
   $quickForm->addElement("textarea", "description", "个人描述信息:", array("rows" => 3, "cols" => 50, "class" => "textBox"));
   $radio[] = &$quickForm->createElement("radio", null, null, "以下信息对不外公开", "1");
   $radio[] = &$quickForm->createElement("radio", null, null, "以下信息对外公开", "0");
   $quickForm->addGroup($radio, "secret");
   //?如何设置默认选中为身份证?
   //中转的办法,设默认值
   $quickForm->addElement("text", "idnuber", "证件号码:", array("size" => 30, "maxlength" => 30));
   $radio2[] =  $quickForm->createElement("radio", "idtype", null, "身份证", null, array("value" => 1, "checked" => "true"));
   $radio2[] =  $quickForm->createElement("radio", "idtype", null, "其它证件", null, array("value" => 2));
   $quickForm->addGroup($radio2);
   $quickForm->addElement("text", "realname", "真实姓名:", array("size" => 20, "maxlength" => 30));
   $quickForm->addElement("select", "gender", "性别:", array("male" => "男", "female" => "女"));
   $quickForm->addElement("date", "born", "出生于:", array("format" => "Y 年m 月d", "minYear" => 1940, "maxYear" => 1995));
   $quickForm->addElement("select", "country", "所在国家:", $country);
   $quickForm->addElement("select", "city", "省(市):", $city);
   $quickForm->addElement("text", "town", "市(县):", array("size" => 20, "maxlength" => 20));
   $quickForm->addElement("text", "address", "联系地址:", array("size" => 50, "maxlength" => 50));
   $quickForm->addElement("text", "zipcode", "邮政编码:", array("size" => 20, "maxlength" => 20));
   $quickForm->addElement("text", "phone", "联系电话:", array("size" => 20, "maxlength" => 20));
   $quickForm->addElement("text", "company", "所在单位:", array("size" => 30, "maxlength" => 30));
   $quickForm->addElement("text", "department", "所在部门:", array("size" => 20, "maxlength" => 20));
   $quickForm->addElement("select", "industry", "所在行业:", $industry);
   $quickForm->addElement("select", "source", "主要在哪里
访问我们的网站:", $from);
   $quickForm->addElement("text", "webpage", "个人主页:", array("size" => 50, "maxlength" => 50));
   $quickForm->addElement("submit", null, "注册用户");

   //设定表单的规则
   $quickForm->applyFilter("name", "trim");
   $quickForm->addRule("name", "用户登录昵称必须填写!!", "required");
   $quickForm->addRule("pass", "密码不能为空", "required");
   $quickForm->addRule("email", "电子邮件EMAIL不能为空", "required");   
   $quickForm->addRule("passquestion", "请填写密码提示问题", "required");
   $quickForm->addRule("passanswer", "请填写密码提示答案", "required");
   $quickForm->addRule("idnuber", "请填写证件号码", "required");
   $quickForm->addRule("realname", "请填写真实姓名", "required");
   $quickForm->addRule("gender", "性别不能为空", "required");
   $quickForm->addRule("born", "出生日期不能为空", "required");
   $quickForm->addRule("country", "国家不能为空", "required");
   $quickForm->addRule("city", "城市不能为空", "required");
   $quickForm->addRule("address", "请填写你的联系地址", "required");
   
   $quickForm->addRule("name", "用户登录呢称最少为5个字符", "minlength", 5);
   $quickForm->addRule("pass", "密码太简单,不能少于5位", "minlength", 5);
   $quickForm->addRule(array("pass", "repass"), "两次的密码不一致", "compare");
   $quickForm->addRule("email", "请输入正确的EMAIL地址(user@domain)", "email");
   $quickForm->addRule("idnuber", "证件号码不能少于5位", "minlength", 5);
   $quickForm->addRule("idnuber", "证件号码只能是英文字母或数字"



성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.