免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1298 | 回复: 0

17 十三章 想函数传递表单数据 [复制链接]

论坛徽章:
0
发表于 2011-12-22 08:54 |显示全部楼层

  1. <?php
  2.         // 这里提交的 _POST['name1'] 与 html中 name = name1 要一致

  3.         function validataEmail($email)
  4.         {
  5.                 $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,6})$";
  6.                 if(eregi($regexp,$email))return 1;
  7.                 else
  8.                         return 0;
  9.         } 

  10.         if(isset($_POST['submit']))
  11.         {
  12.                 $name = htmlentities($_POST['name1']);
  13.                 $email = htmlentities($_POST['email1']);
  14.                 printf("hi %s <br />",$name);
  15.                 if(validataEmail($email))
  16.                         printf("the address %s will soon be a spam-magnet <br />",$email);
  17.                 else
  18.                         printf("bad email <br />");
  19.         }
  20. ?>

  1. <form action = "test7.php" method = "post">
  2.         <p>
  3.                 Name:<br />
  4.                 <input type="text" id = "name" name = "name1" size = "20" maxlength = "40" />
  5.         </p>
  6.         <p>
  7.                 Email Address:<br />
  8.                 <input type = "text" id = "email" name = "email1" size = "20" maxlength = "40" />
  9.         </p>
  10.         <input type = "submit" id = "submit" name = "submit" value = "Go" />
  11. </form>

  12. //注意 name = "name 1" 与 POST中 配合






您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP