views:

16

answers:

2

I have a form that has a series of check boxes and some line items have a text input next to them that defines quantity of the item.

<input type="checkbox" name="measure[][input]" value="<?=$item->id?>"> 
<input class="item_mult" type="text" name="measure[][input]" /> 

What is the best way to capture the integer from the input field and have it correspond to the check box so I can use it to calculate the total later on?

+1  A: 

You can give your array a name/id to associate them, just add it into the name attribute:

<input type="checkbox" name="measure[1][my_checkbox]" value="<?=$item->id?>"> 
<input class="item_mult" type="text" name="measure[1][my_text]" /> 
Topher Fangio
+1  A: 
<input type="checkbox" name="measure[<?php echo $item->id; ?>][checked]" value="<?php echo $item->id; ?>"> 
<input class="item_mult" type="text" name="measure[<?php echo $item->id; ?>][input]" />

That should give the values $measure[1]['checked'] (only present if checked) and $measure[1]['input']

I corrected your short tags - they're a bad idea, as they are disabled in php by default so can cause issues if you move servers

adam
The short tags are disabled by default? I just setup two Debian-based servers and they work fine. I didn't change the config files at all.
Topher Fangio
Ahh, just googled and I was wrong - they're not disabled by default, but are frowned upon (due to code portability) and will be phased out in PHP 6
adam