首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > PHP > 一个表单数据检查思路....
【标  题】:一个表单数据检查思路....
【关键字】:....
【来  源】:http://blog.csdn.net/km3945/archive/2007/01/22/1490207.aspx

一个表单数据检查思路....

 1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta http-equiv="content-language" content="zh-CN" /><meta http-equiv="pragma" content="no-cache" /><meta http-equiv="expires" content="0" /><meta http-equiv="MSThemeCompatible" content="Yes" /><meta http-equiv="imagetoolbar" content="no" />
 3<meta http-equiv="widow-target" content="_top" /><meta name="robots" content="index, follow" /><meta name="author" content="3945, ljm77@km169.net" />
 4<meta name="keywords" content="" /><meta name="description" content="" /><meta name="copyright" content="Copyright 3945 All Rights Reserved" />
 5<title>无标题文档</title>
 6<style type="text/css"><!--
 7a, a:link{text-decoration: none; color:#000000; font-size:9pt;}    a:visited{text-decoration: none; color:#000000;}    a:hover{text-decoration: underline; color:red;}
 8body, td, p, li, div, select{font-size:9pt; font-family:"宋体";}
 9--></style>
10</head>
11
12<body>
13
14
15<?php
16/*
17检测表单数据,
18一至以来都想做个方便一点的表单数据检查程序.但看来看去没有什么好方法,
19这是今天想到的.利用表单元素的NAME属性.
20我们在定义表单元素时,把NAME的属性定义成带数据类型的格式如:
21<input type="text" name="test_s_n" />
22该IPNUT是s[String],n[noNull],test就是表单的表意词.
23意思就是TEST是字符串,不能为空.
24有些东西想的不是太清楚.只是一种思路.
25下面是一个小DEMO
26*/
27if($_SERVER['REQUEST_METHOD'== 'POST')
28{
29    checkPost($_POST);
30    echo '<pre>'.print_r($_POST, true).'</pre>';
31}
32
33function checkPost($data)
34{
35    foreach($data as $key=>$val)
36    {
37        list($name, $type= explode('_', $key, 2);
38        if(!is_null($type))
39        {
40            if(!ck($val, $type)) die($key .'类型不匹配!');
41        }
42    }
43}
44
45function ck($value, $type)
46{
47    $a =array();
48    $types = explode('_', $type);
49    foreach($types as $t)
50    {
51        if('s' == $t)
52        {
53            $a[$t= is_string($value);
54        }
55        if('i' == $t)
56        {
57            $a[$t= is_numeric($value);
58        }
59        if('n' == $t)
60        {
61            $a[$t= !empty($value);
62        }
63    }
64    return in_array(true, $a);
65}
66?>
67<form name="form1" method="post" action="">
68    <input type="text" name="test_s_n" />
69    <input type="submit" value="Submit" name="b1" />
70    <input type="reset" value="Reset" name="b3" />
71</form>
72</body>
73</html>
 
给Prototype.js减肥:【上一篇】
会员系统整合的想法[择]:【下一篇】
【相关文章】
  • window.scroll 浏览器滚动条的参数总结.......... [转]
  • ASP无组件上载,带进度条,多文件上载。。 is error , i modify it then OK...............
  • 虽然把那些as和他的思路 看的差不多明白了....但还是做不出来
  • M等待中 ?? 寂野2002-08-17, 01:37 AMsigh........ 其实shape很好做的
  • 一个猜字母的小游戏,也是我的第一个小游戏程序....
  • sizeof............
  • 技术交流..................
  • Prototype.js 源码学习(不段更新中......)
  • 很强的表单验证类(抄来的....)
  • profiling in vc6 ... 没vtune....vc7 玩不了
  • 【随机文章】
  • 对Acegi ACL扩展的构想
  • 第三道虎纹:自动包装机制
  • VC数字图像处理编程讲座之四
  • Informix安装手册(SCOUNIX环境)
  • 病毒名称 爱我(Worm.MSNLoveme)
  • shell中有关字符串的处理
  • 用户IP、浏览器、操作系统
  • Linux 网管 123 --- 第5章. 组态 X Window 系统 -1.使用 X-
  • 今天为何选择cublog.cn
  • 基于反向代理的Web缓存加速-----可缓存的CMS系统设计
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.