samedi 13 août 2016

Reading dynamic checkbox array in php/html

I have multiple form fields which are created dynamically .

<label><input type="text" name="txtAmt[]">Amount</label>
<label><input type="checkbox" name="cbMarkPaid[]">Mark as Paid</label>

I use post method to submit the for to php file.I know that the checkbox won't send the data to the server when you did not check it.But i want to know the indices of the checkboxes which are not checked.

E.g. If i have 4 checkboxes cb1,cb2,cb3,cb4 and if cb3,cb4 is checked . then php recieves an array with two items : array(2) { [0]=> string(2) "on" [1]=> string(2) "on" } But i want the array to be as :array(2) { [0]=> string(2) "off" [1]=> string(2) "off" [2]=> string(2) "on" [3]=> string(2) "on"}.

Please not isset($_POST['cbMarkPaid'][]) is also giving the same output Thank you




Aucun commentaire:

Enregistrer un commentaire