mercredi 31 janvier 2018

How to post blank array (neither NULL nor "") values in php in no checkbox is checked

Bare me if I am asking something very basic as I am new to php. I have a list of checkboxes and if checked their values are posted to json file which is working fine. When user uncheck all of them I get NULL value in array and if I set its value="" its returns depends :[""]. what i want is if user did not check any checkbox it returns depends:[] only neither NULL nor "". Here is my code.

Linked With

      <input type="checkbox" name="depends[]" value="1"  id="ch2" > 1
      <input type="checkbox" name="depends[]" value="2"  id="ch3" > 2
     <input type="checkbox" name="depends[]" value="3"  id="ch5" > 3
    <input type="checkbox" name="depends[]" value="4"  id="ch6" > 4
    <input type="checkbox" name="depends[]" value="5"  id="ch7" > 5
    <input type="checkbox" name="depends[]" value="6"  id="ch8" > 6
    <input type="checkbox" name="depends[]" value="7"  id="ch9" > 7

in php code i am calling it as

        'depends'=>$_POST['depends']

Thanks in advance for your time and help.




Aucun commentaire:

Enregistrer un commentaire