如何在同一时间提交多个表格

如何在同一时间提交多个表格

问题描述:

我有两种形式工作正常,有一个小问题,我无法弄清楚。如何在同一时间提交多个表格

两种表格都提交数据,但是当我将物品提交给购物车时,它会更新或插入我为物品1更新的数量,如果您为任何其他物品选择不同的数量并添加它将插入数量第一个项目只有不选择的项目数量。

多个表单提交Javascript代码

<script type="text/javascript"> 
submitForms = function(){ 
    document.forms["quantity"].submit(); 
    document.forms["submit"].submit(); 
} 
</script> 

表#1数量

<form class="" id="<?php echo $mitem_ida; ?>" name="quantity" action="item_process.php" method="post" target="votar"> 
<div class="quantity-wrap"> 
<div class="quantity" style="margin-bottom: -12px;"> 
<input type="button" value="-" onclick="javascript: subtractQtyz('<?php echo $mitem_ida; ?>');" > 
<input name="qtyz" type="number" readonly class="qty" id="quantityx_<?php echo $mitem_ida; ?>" value="1" /> 
<input type="button" value="+" onclick="javascript: document.getElementById('quantityx_<?php echo $mitem_ida; ?>').value++;"> 
<font style="color: black; text-shadow: 2px 2px 3px #999999;">كمية</font> 
</div> 
</div> 
</form> 

表#2等领域

<form class="formItem" id="<?php echo $mitem_ida; ?>" name="quantity" action="item_process.php" method="post" target="votar"> 
<input type="hidden" value="<?php echo $mitem_ida; ?>" name="item_id"> 
<input type="hidden" value="<?php echo $mitem_pricea; ?>" name="price_id"> 

<?php if ($detect->isMobile()) { ?> 
    <div class="item-price" style="background-color: green; margin-top:-35px; margin-left: 105px;"> 
<?php }else{ ?> 
    <div class="item-price" style="background-color: green; margin-top:-92px; margin-left: 105px;"> 
<?php } ?>        
<span class="amount"> 

<a style="color: white;" href="#" onclick="submitForms()" > 
<font style="font-size: 12px;"> 
<?php if ($lang == 'en') { 
echo "Add To Cart"; 
}else{ 
echo "<b>أضف إلى السلة</b>"; 
} 
?> 
&nbsp;&nbsp;&nbsp;&nbsp; 
</font> 
</a> 
</span> 
</div></form> 

PHP MySQL查询

if (isset($_SESSION['ses_user_id']) == true){ 
$ses_mem  = $_SESSION['ses_user_id']; 
}else{ 
$ses_mem = session_id(); 
} 

$insitID = mysql_real_escape_string($_POST['item_id']); // 2nd form 
$inspr  = mysql_real_escape_string($_POST['item_price']); // 2nd form 
$iqty  = mysql_real_escape_string($_POST['qtyz']); //1st form 

mysql_query(" 
insert into temp_cart (item_id, price_id, ses_mem, qty) values (
'".$insitID."','".$inspr."','".$ses_mem."','".$iqty."' 
) 
"); 
+3

的框架您无法在某个时间提交两种表单,您应该使用ajax或其他方法执行此操作... – aidinMC

调用提交功能将触发重新加载整个页面,从而以第二个呼叫提交将永远不会被执行(检查here,它重新加载的iframe)。

要提交两个表单而不丢失数据,您应该使用AJAX。要么使用natively,要么使用如jQuery