我正在尝试从其他表单提交表单。
我点击了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&value=n&startRow=10" class="form_arrows " onClick="document.getElementById('navForm').submit()">Previous</a>
<a href="index.php?page=home&value=p&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' />
提交
答案 0 :(得分:0)
您没有提交其他表格。 “A”不是表格元素。
您不会仅仅通过将其置于achor的href中来更改表单操作
从onclick返回false,因此您不会重新加载页面:
<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&value=n&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&value=n&startRow=0" class="form_arrows" id="prev">Previous</a>
<a href="index.php?page=home&value=p&startRow=10" class="form_arrows" id="next">Next</a>