moleculo Posted December 4, 2007 Share Posted December 4, 2007 Hello. I'm trying to post an array of various rows all at once. One field has the "checkbox" type, the other has the "text" type. I want it to post all the values for both fields but only for the rows that are checked (could be more than 1). I can get the checkbox type to post, but not the text. <form action=update.php method=post> <input type=checkbox name=no[] value=$row[1]></input> <input type=text name=qty[] value=$row[2]></input> </form> update.php: if(isset($_POST['update'])) { for ($i=0; $i<count($_POST['no']);$i++) { $no = $_POST['no'][$i]; $qty = $_POST['qty'][$i]; echo "no = $no<br>"; echo "qty = $qty<br>"; } } Using the above code, I get the correct values for $no, but for $qty, I get blank. Any ideas what I'm doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/80131-need-help-on-posting-an-array-of-text-that-are-checkboxed/ Share on other sites More sharing options...
bibby Posted December 5, 2007 Share Posted December 5, 2007 You should really keep quotes around your attributes. If the text contained a space, you'd be sunk. Other than that, text inputs posting as part of an array should work fine. such as.. <? print_r($_POST); ?> <form method="post"> <input type="text" name="qty[]" /><br /> <input type="text" name="qty[]" /><br /> <input type="text" name="qty[]" /><br /> <input type="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/80131-need-help-on-posting-an-array-of-text-that-are-checkboxed/#findComment-406607 Share on other sites More sharing options...
moleculo Posted December 5, 2007 Author Share Posted December 5, 2007 d'oh! Ok, I fixed it and that eliminated the "blank" problem. Thank you for your help on that. But the problem now is it's posting the values from the text field (qty) in the order they are in the table, rather than posting the values that I check. For example, if I have multiple rows like this: [checkbox1] [qty1] [checkbox2] [qty2] [checkbox3] [qty3] When I click checkbox1 and 3, It echoes qty1, and 2. How can I get it to echo the qty that corresponds with the appropriate row that is checked? Quote Link to comment https://forums.phpfreaks.com/topic/80131-need-help-on-posting-an-array-of-text-that-are-checkboxed/#findComment-406966 Share on other sites More sharing options...
Barand Posted December 5, 2007 Share Posted December 5, 2007 As only checked c/boxes are posted, <?php foreach ($_POST['no'] as $i => $no) { echo $no, ' ', $_POST['qty'][$i], '<br/>'; } PS. pre-index the items in the form <form action=update.php method=post> <input type=checkbox name=no[1] value=$row[1]></input> <input type=text name=qty[1] value=$row[2]></input> <input type=checkbox name=no[2] value=$row[1]></input> <input type=text name=qty[2] value=$row[2]></input> </form> Quote Link to comment https://forums.phpfreaks.com/topic/80131-need-help-on-posting-an-array-of-text-that-are-checkboxed/#findComment-407121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.