jeudi 22 octobre 2015

Setting value of unchecked checkbox php

I have this form

<tr>
    <td>
        <input type="hidden" name="po[]" value="<?php echo $ord['id'] ?>" />
        <input type="hidden" name="acts[]" value="1" />
        <input id="acts" value='2' type="checkbox" <?php echo $check ?> name="acts[]" />
    </td>
    <td><img src="<?php echo $pnme['icon'] ?>" style="height: 25px; width: 25px; vertical-align: middle;" /><?php echo $pnme['name'] ?></td>
    <td><input id="per" style="background: #BDBDBD; width: 100px;" name="per[]" size="5" type="text" class="small" value="<?php echo $ord['fee'] ?>" /></td>
    <td><input id="dol" style="background: #BDBDBD; width: 100px;" name="dol[]" size="5" type="text" class="small" value="<?php echo $ord['cost'] ?>" /></td>
</tr>

I am trying to get it to pass a different value if the checkbox is not checked, I have a hidden input but it does not pass the values correctly where I need it to, when the form posts this is how I handle the information

    $po = implode(",", $_POST['po']);
    $po = explode(",", $po);

    $fee = implode(",", $_POST['per']);
    $fee = explode(",", $fee);

    $co = implode(",", $_POST['dol']);
    $co = explode(",", $co);

    $act = implode(",", $_POST['acts']);
    $act = explode(",", $act);
    print_r($act);
    for ($i = 0; ; $i++) {
    if ($i > count($po) - 1) {
        break;
    }

for example if I check every box it sets the array like this

Array ( [0] => 1 [1] => 2 [2] => 1 [3] => 2 [4] => 1 [5] => 2 [6] => 1 [7] => 2 [8] => 1 [9] => 2 [10] => 1 [11] => 2 [12] => 1 [13] => 2 [14] => 1 [15] => 2 [16] => 1 [17] => 2 [18] => 1 [19] => 2 [20] => 1 [21] => 2 ) 

even though ever single one should have the value of 2

I added this trying to set the initial value to 1 thinking that if the box is checked it would overwrite the value, but this doesn't seem to be the case

I am not sure how to handle this situation and make it work with my processing code.




Aucun commentaire:

Enregistrer un commentaire