Forums / Cotonti / Extensions / Support / Module main page blocking js?

lukgoh
#36533 2012-12-14 00:03

This problem is driving me insane trying to solve it. I will try my best to explain. 

I am trying to build a shopping cart. Categories and products are built with php and each item has an "add to cart" button. I have a single hidden form and js to submit the form. This method works really well for the shopping cart or shop.cart.php (for updating quantities or deleting items) but for some reason it doesn't work at all on shop.main.php it only redirects me to index.php?productid=1&command=add when trying to add items. I have tried everything I can think of. 

$js = 'function addtocart(pid){';
$js .= 'document.form1.productid.value=pid;';
$js .= 'document.form1.command.value="add";';
$js .= 'document.form1.submit();';
$js .= '}';

cot_rc_embed($js);


if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
		$pid=$_REQUEST['productid'];
		addtocart($pid,1);
		cot_redirect(cot_url('shop', 'm=cart', '', true));
		exit();
	}

'PRODUCT_ADD' => cot_inputbox('button', '', 'Add to Cart', array('onclick' => 'addtocart('.$rowproducts['product_id'].')'))

That is a snippet of my shop.main.php but its the only part that isn't working properly. 

<form name="form1">
	<input type="hidden" name="productid" />
    <input type="hidden" name="command" />
</form>

from the tpl.

 

Any help would be much appreciated! 

Luke.