Reputation: 233
I have two forms which are working fine with a little problem where I cannot figure out.
Both forms are submitting data but when I submit the item's to cart it does update or insert the quantity what I have updated for item one, if you choose a different quantity for any other item and add it will insert the quantity of the first item only not the selected items quantity.
Javascript code for multiple form submission
<script type="text/javascript">
submitForms = function(){
document.forms["quantity"].submit();
document.forms["submit"].submit();
}
</script>
Form # 1 Quantity
<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>
Form # 2 other fields
<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>";
}
?>
</font>
</a>
</span>
</div></form>
php mysql query
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."'
)
");
Upvotes: 1
Views: 1898
Reputation: 10064
Calling submit function will trigger a full page reload, hence the second call to submit will never be executed (check it here, it reloads the iframe).
To submit both forms without losing data you should use AJAX. Either natively or using a framework like jQuery
Upvotes: 1