zoukankan      html  css  js  c++  java
  • php 同一个form中,不同的submit处理

    1.每个按钮的名字都设置成一个,比如说Submit。然后在接受页面中判断这个值,  
      根据值的不同采取不同动作就是了。  

      比如:  
      file1.php  
      <form   action="file2.php"   method="post">  
      <input   type="text"   name="ok">  
      <input   type="submit"   name="mySubmit"   value="添加">  
      <input   type="submit"   name="mySubmit"   value="修改">  
      <input   type="submit"   name="mySubmit"   value="删除">  
      </form>  
       
      file2.php  
      <?  
      $action   =   $HTTP_POST_VARS["mySubmit"];  
      switch   ($action)  
      {  
      case   "添加":  
      //省略代码  
      break;  
      case   "修改":  
      //略  
      break;  
      case   "删除":  
      //略  
      break;  
      }  

      ?>

    2. 第二个办法

    使用javascript调用form的submit方法,同时编写简单的脚本将添加、删除、更新之类的值通过hidden对象传过去。  
      file1.php  
      <script>  
      add()  
      {  
      document.all.item("action")="add";  
      ...  
      其它语句,比如校验之类  
      ...  
      document.all.item("form1").submit();  
      }  
      del()  
      {  
      document.all.item("action")="del";  
      ...  
      其它语句,比如校验之类  
      ...  
      document.all.item("form1").submit();  
      }  
      modify()  
      {  
      document.all.item("action")="modify";  
      ...  
      其它语句,比如校验之类  
      ...  
      document.all.item("form1").submit();  
      }  
      </script>  
      <form   id=form1   method=post   action=file2.php>  
      <input   name=submitbutton   type=button   value=添加   onclick=add()   />  
      <input   name=submitbutton   type=button   value=删除   onclick=del()   />  
      <input   name=submitbutton   type=button   value=更新     onclick=modify()/>  
      <input   name=action   type=hidden   value=""   />  
      </form>  
       
      file2.php  
      <?  
      switch($HTTP_POST_VARS['action'])  
      {  
      'add':  
            ...  
            break;  
      'del':  
            ...  
            break;  
      'modify':  
            ...  
            break;  
      default:  
            ...  
      }  
      ?> 

     转http://topic.csdn.net/t/20021024/17/1122497.html

  • 相关阅读:
    EasyUI基础searchbox&amp;progressbar(搜索框,进度条)
    git 仓库
    “农民代码”讨论
    多线程和多进程之间的区别
    move_uploaded_file
    在form里面,放了四个UEditor,怎么在后台分别获取它们值
    ThinkPHP模板IF标签用法详解
    Tp框架查询分页显示与全部查询出来显示运行时间快慢有区别吗?
    百度UEditor基本使用
    织梦DedeCms获取当前页面URL地址的调用方法
  • 原文地址:https://www.cnblogs.com/likwo/p/1717472.html
Copyright © 2011-2022 走看看