I’m try to combine a checkbox values with a text field into one variable, so that when I echo it out it shows the correct fields values.
I want to combine the post of the checkbox with that of the quantity text field, because there are several items i’m using a forloop but can’t seem to combine both values into one so that it creates a new table row with that item name on the left and the quantity on the right.
<tr>
<td>
<input type="checkbox" name="check[]" value="<?php echo get_post_meta($post->ID, '_stitle', true); ?>" />
</td>
<td>
<input id="quantity" name="check[quantity]" type="text" maxlength="3" /><br />
</td>
$data = $_POST['check'];
foreach ($data as $value) {
$item .= '<tr style="background: #eee;">
<td>Item: </td>
<td>'.$value.'</td>
</tr>';
}
You should probably change:
to:
You scalar your checkbox but not the textfield.
Also, it would probably simpler to relate your two fields with a for, as the array key’s will be the same between each checkbox and input field.
Example:
Also, note the -2 from sizeof $_POST. You must subtract both your quantity key and your offset to set your ending point equal to that since you are counting from 0.