从其他表格提交表格

时间:2014-07-14 08:11:08

标签: php html

我正在尝试从其他表单提交表单。

我点击了NEXT,但表单“navForm”没有提交。

echo $_POST['check_if_send'];
<form method='post' action='index.php?page=home&act=multi_edit' name='mainTable'>
    <a href="#" class="form_arrows left" onClick="document.getElementById('mainTable').submit()">Multi Update</a>
    <a href="index.php?page=home&amp;value=n&amp;startRow=10" class="form_arrows " onClick="document.getElementById('navForm').submit()">Previous</a>
    <a href="index.php?page=home&amp;value=p&amp;startRow=10" class="form_arrows " onClick="document.getElementById('navForm').submit()">Next</a>
</form>
<form method='post' action='index.php?page=home&act=search' id="navForm" name="navForm">
    <input type='hidden' name='check_if_send' value='some_value'  />

提交     

1 个答案:

答案 0 :(得分:0)

  1. 您没有提交其他表格。 “A”不是表格元素。

  2. 您不会仅仅通过将其置于achor的href中来更改表单操作

  3. 从onclick返回false,因此您不会重新加载页面:


  4.     <a href="#" class="form_arrows left" 
        onClick="document.getElementById('mainTable').submit(); 
        return false">Multi Update</a>
    

    也许你的意思是

    function nav(idx) {
      var form = document.getElementById('navForm'),
          url = "index.php?page=home&amp;value=n&amp;startRow="+idx;
      form.action=url; 
      form.submit();
      return false;
    }
    window.onload=function() {
      document.getElementById("previous").onclick=document.getElementById("next").onclick=function() {
      nav(this.getAttribute("data-idx"));
      }
    }
    
    使用

    <a href="#" class="form_arrows" id="prev" data-idx="0">Previous</a>
    <a href="#" class="form_arrows" id="next" data-idx="10">Next</a>
    

    function nav(link) {
      var form = document.getElementById('navForm');
      form.action=link.href; 
      form.submit();
      return false;
    }
    window.onload=function() {
      var links = document.querySelectorAll(".form_arrows");
      for (var i=0;i<links.length;i++) links[i].onclick=function() {
        nav(this);
      }
    }
    
    使用

    <a href="index.php?page=home&amp;value=n&amp;startRow=0" class="form_arrows" id="prev">Previous</a>
    <a href="index.php?page=home&amp;value=p&amp;startRow=10" class="form_arrows" id="next">Next</a>