Javascript 我有3张表格和一个提交按钮,我只是从1张表格收到信息
我把信息放在我的表格里,我只是收到了3号表格的1,而不是其他表格 这是我在页面中的代码 我该怎么解决这个问题?有人能帮我解决这个问题吗Javascript 我有3张表格和一个提交按钮,我只是从1张表格收到信息,javascript,php,html,forms,Javascript,Php,Html,Forms,我把信息放在我的表格里,我只是收到了3号表格的1,而不是其他表格 这是我在页面中的代码 我该怎么解决这个问题?有人能帮我解决这个问题吗 // my code to the forms in the page <div style="margin-left:110px;float:left !important ;clear:both;"> <?php echo ' <form method="post" action="testing.php" id="form1"
// my code to the forms in the page
<div style="margin-left:110px;float:left !important ;clear:both;">
<?php
echo '
<form method="post" action="testing.php" id="form1">
<textarea style="height:150px;width:250px;" name="message"></textarea>
</form>
';
?>
</div>
<div>
<?php
echo '
<form method="post" action="testing2.php" id="form2">
<textarea style="margin-left:80px;height:150px;width:250px;" name="message">Write your opinon here</textarea>
</form>
';
?>
</div>
<div>
<?php
echo '
<form method="post" action="testing3.php" id="form3">
<textarea style="margin-left:80px;height:150px;width:250px;" name="message"></textarea>
</form>
';
?>
</div>
//将我的代码添加到页面中的表单中
我的表单javascript:
<script>
submitForms = function() {
document.forms["form1"].submit();
document.forms["form2"].submit();
document.forms["form3"].submit();
return true;
}
</script>
<input type="button" value="submit" onclick="submitForms()" />
submitForms=函数(){
document.forms[“form1”].submit();
文件。表格[“表格2”]。提交();
文件。表格[“表格3”]。提交();
返回true;
}
我的表单的php代码如下(其他表单的代码与我的相同):
//连接到mysql的php代码
代码的操作链接指向三个不同的位置,另外每个表单都需要有一个唯一的提交按钮。如果需要获取每个表单的输入,那么为提交按钮设置一个id,并在php代码中检查是否设置了。
像这样:
您有3个单独的表单,在javascript中只有first.submit()。
要么将所有内容合并到一个表单(您仍然可以有3个按钮并检查按下的内容),要么编写ajax代码提交3个不同的表单。如果您使用以下代码,则代码是正确的:
<script>
submitForms = function() {
document.forms["form1"].submit();
document.forms["form2"].submit();
document.forms["form3"].submit();
return true;
}
</script>
<input type="button" value="submit" onclick="submitForms()" />
submitForms = function(){
document.getElementById("form1").submit();
document.getElementById("form2").submit();
document.getElementById("form3").submit();
}
您可以使用ajax来实现这一点。请检查我的答案@Ahmad Saidan
if(isset($_POST['submit_id'])){
}
<script>
submitForms = function() {
document.forms["form1"].submit();
document.forms["form2"].submit();
document.forms["form3"].submit();
return true;
}
</script>
<input type="button" value="submit" onclick="submitForms()" />
<form method="post" action="testing1.php" name="form1">
<form method="post" action="testing2.php" name="form2">
<form method="post" action="testing3.php" name="form3">
submitForms = function(){
document.getElementById("form1").submit();
document.getElementById("form2").submit();
document.getElementById("form3").submit();
}