jeudi 16 juin 2016

How to retrieve the checkbox that is not checked using POST in PHP?

I have a dynamic table form. And there is a column for checkbox. My problem is I want to get also the checkbox that is not checked.

I want to have an end result like this using array.

selected = array(
   '1' => 1,
   '2' => 0, //not checked
   '3' => 1,
   '4' => 1
)

The index of array correspond which row does the checkbox belongs. Like this:

<tr>
    <td><input type="checkbox" name="t_liquadated[]" value="1" />
</tr>
<tr>
    <td><input type="checkbox" name="t_liquadated[]" value="1" />
</tr>
<tr>
    <td><input type="checkbox" name="t_liquadated[]" value="1" />
</tr>
<tr>
    <td><input type="checkbox" name="t_liquadated[]" value="1" />
</tr>

Here's my real code

$('#add-invoice-list').on('click', function(){

    set_count++;

    var row_html  = '<tr id="inv-' + set_count + '">';
        row_html += '   <td></td>';
        row_html += '   <td><input type="text" name="t_soa_amount[]" class="text-right" /></td>';

        row_html += '   <td><select name="t_soa_prepared_by[]" class="officer_dropdown form-control"></select></td>';
        row_html += '   <td><input type="text" name="t_soa_date_prepared[]" class="text-center datepicker corner_border" readonly="readonly" /></td>';
        row_html += '   <td><input type="text" name="t_invoice_amount[]" class="text-right" /></td>';

        row_html += '   <td><select name="t_invoice_prepared_by[]" class="officer_dropdown form-control"></select></td>';
        row_html += '   <td><input type="text" name="t_invoice_date_prepared[]" class="text-center datepicker corner_border" readonly="readonly" /></td>';
        row_html += '   <td class="text-center"><input type="checkbox" name="t_liquadated[]" value="1" /></td>';
        row_html += '   <td class="text-center"><button type="button" class="btn btn-danger btn-sm add_inv" onClick="removeInvoiceRow(' + set_count + ')"><span class="fa fa-trash-o"></span></button></td>';
        row_html += '</tr>';

    if(initial == 1) {
        $('#inv-1').after(row_html);
        initial++;
    } else {
        $('#inv-' + initial).after(row_html);
        initial++;
    }

    var c = $('.officer_dropdown').length;
    $('.officer_dropdown').html("<?php echo $options_officer; ?>");

});

And I am passing this using POST

$invoice_list = array(
                't_soa_amount'              =>  $this->input->post('t_soa_amount'),
                't_soa_prepared_by'         =>  $this->input->post('t_soa_prepared_by'),
                't_soa_date_prepared'       =>  $this->input->post('t_soa_date_prepared'),
                't_invoice_amount'          =>  $this->input->post('t_invoice_amount'),
                't_invoice_prepared_by'     =>  $this->input->post('t_invoice_prepared_by'),
                't_invoice_date_prepared'   =>  $this->input->post('t_invoice_date_prepared'),
                't_liquadated'              =>  $this->input->post('t_liquadated'),         
            );

            fd($invoice_list);

I hope you can help me. Thanks.




Aucun commentaire:

Enregistrer un commentaire