djones Posted December 9, 2008 Share Posted December 9, 2008 I have a cart form that holds: cart id (hidden input) part number (input) configured ( y/n checkbox) config file (textarea) quantity (input) If I have say 3 line items in my cart when I post through the loop of item and the last item was checked y for configured it applies it to the first item. How is that? How can I fix it? My test loop looks like this: foreach($_POST['cart_id'] as $n=>$cart_id_u){ $qty_u = $_POST['qty'][$n]; $configured = $_POST['configured'][$n]; $config = $_POST['config'][$n]; $inv_id = $_POST['inv_id'][$n]; echo '<p>'; echo '<strong>'; echo $cart_id_u.'<br />'; echo $inv_id.'<br />'; echo $qty_u.'<br />'; echo $configured.'<br />'; echo $config; echo '</strong>'; echo '</p>'; echo '<hr />'; } Again for some reason if I check the last checkbox item in the cart it applies it to the first one. Here is sample out put where I actually checked part number: 4212904L1 and it applied the checkbox to IAD2431-16FXS. 323 IAD2431-16FXS 1 Y ----------------------- 324 A1704-0131-10-05 1 ----------------------- 328 4212904L1 1 test ----------------------- All if my form field names are in an array, such as cart_id[], configured[] ...etc Link to comment https://forums.phpfreaks.com/topic/136248-solved-posting-order-for-checkboxes/ Share on other sites More sharing options...
rhodesa Posted December 9, 2008 Share Posted December 9, 2008 instead of confugred[] and such, put the cart_id in the brackets. so your form elements look like: configured[5] configured[22] etc... still keep cart_id[] though, as you can use that to loop on. so, your form elements would end up something similar to this: cart_id[] = 5 qty[5] = 3 configured[5] = 'on' inv_id[5] = 'def' cart_id[] = 8 qty[8] = 1 configured[8] = 'on' inv_id[8] = 'def' etc get it? edit: and the loop would look like: foreach($_POST['cart_id'] as $cart_id){ $qty_u = $_POST['qty'][$cart_id]; $configured = $_POST['configured'][$cart_id]; $config = $_POST['config'][$cart_id]; $inv_id = $_POST['inv_id'][$cart_id]; Link to comment https://forums.phpfreaks.com/topic/136248-solved-posting-order-for-checkboxes/#findComment-710734 Share on other sites More sharing options...
djones Posted December 9, 2008 Author Share Posted December 9, 2008 Tested and working. Thanks. Link to comment https://forums.phpfreaks.com/topic/136248-solved-posting-order-for-checkboxes/#findComment-710740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.