Multiple checkboxes in an AJAX calls I've been developing this phonegap app and I'm stuck with a few things and one of them is multiple checkboxes - I hope you can help.

I've got the below code

HTML

&lt;input type="date" id="date" /&gt;
&lt;input type="hidden" id="hidden"&gt;
&lt;fieldset id="oyuncuKategori"&gt;
    &lt;legend&gt;Kategori&lt;/legend&gt;
    &lt;div class="roundedOne"&gt;
        &lt;input type="checkbox" id="oyuncu" name="kategori" value="oyuncu" class="squareTwo" /&gt;
        &lt;label for="oyuncu"&gt;Oyuncu&lt;/label&gt;
    &lt;/div&gt;
    &lt;div class="roundedOne"&gt;
        &lt;input type="checkbox" id="yardimci_oyuncu" name="kategori" value="yardimci_oyuncu" class="squareTwo" /&gt;
        &lt;label for="yardimci_oyuncu"&gt;Yardımcı oyuncu&lt;/label&gt;
    &lt;/div&gt;
    &lt;div class="roundedOne"&gt;
        &lt;input type="checkbox" id="cocuk_oyuncu" name="kategori" value="cocuk_oyuncu" class="squareTwo" /&gt;
        &lt;label for="cocuk_oyuncu"&gt;Çocuk oyuncu&lt;/label&gt;
    &lt;/div&gt;
    &lt;div class="roundedOne"&gt;
        &lt;input type="checkbox" id="stand_hostesi" name="kategori" value="stand_hostesi" class="squareTwo" /&gt;
        &lt;label for="stand_hostesi"&gt;Stand hostesi&lt;/label&gt;
    &lt;/div&gt;
&lt;/fieldset&gt;


JavaScript

$("input[type='date']").on("change", function () {
    // var checkbox = $("#oyuncuKategori").serialize();
    var checkboxes = '';
    $('input[name=kategori]:checked').each(function(i, e) {
        checkboxes += '&amp;node[field_kategorisi][und][value]='+$(this).val();
    });
    console.log(checkboxes);
    monthNames = [
        "Oca", "Şub", "Mar",
        "Nis", "May", "Haz", "Tem",
        "Ağu", "Eyl", "Eki",
        "Kas", "Ara"];
    date = new Date($("input").val());
    day = date.getDate();
    monthIndex = date.getMonth();
    year = date.getFullYear();
    finalDate = day + ' ' + monthNames[monthIndex] + ' ' + year;
    $.ajax({
        url: 'http://www.rejicast.com/services/node.json',
        type: 'post',
        dataType: 'json',
        data: 'node[type]=oyuncu&amp;node[title]=testnomikos456&amp;node[language]=und'+ checkboxes +'&amp;node[field_dogum_tarihi][und][0][value][date]=' + finalDate +',
        success: function (data) {
            console.log(JSON.stringify(data));
        },
        error: function (xhr, status, message) {
            console.log(xhr);
            console.log(status);
            console.log(message);
        }
    });
});


The thing is, this code works for creating a node but and inserts values for field_kategorisi overwriting other values, thus always the last checked box is there, while trying with [und]['+i+'][value] gives me 406: An illegal choice has been detected. Please contact the site administrator. and something like Illegal choice Array in field_kategorisi (I don't remember the English wording) on the server side. I'm really stumped. Can you give me any ideas?

UPDATE: When I make an ajax call, my POST looks like this.


  http://www.rejicast.com/services/node.json?node[type]=oyuncu&amp;node[field_kategorisi][und][0][value]=stand_hostesi&amp;node[field_kategorisi][und][1][value]=yesilcam
Edit: Just looked at the code more closely, and saw this was the Services module.

From https://www.drupal.org/node/1971484#comment-7318114:


  For those of you who will probably have the same problem, here is the correct way to handle LIST type fields (in ex. below field_mosaic_bu):


{
  "type":"TEST",
  "title":"TITLE",
  "uid":"1",
  "field_mosaic_bu":{ "und": ["bu name"] },
  "field_mosaic_var1":{ "und": [{ "value":"test1" }] },
  "field_mosaic_var2":{ "und": [{ "value":"test2" }] },
  "field_mosaic_var3":{ "und": [{ "value":"test3" }] },
  "field_mosaic_image":{ "und": [{ "fid":"4" }] }  
}



  Hope this helps someone. Took me a lot of time to figure this out.




When you get that message from Drupal, it generally means that you have tried to set a form value to a non-allowed value from the perspective of the field configuration. So, for example, field_kategorisi might be a Term Reference field. If you try to set it to a tid that isn't allowed according to the Drupal field configuration, that happens.

If it's a simple checkbox field, then adding the value you want to set to the Allowed Values in the field configuration should solve the issue.

If this doesn't help, please provide more information about the Drupal-side field configuration and whether you are using the form Drupal generates or not. It embeds various things like the form ID, form build ID, and so on into its form markup, so if problems persist, it could be related to it not receiving something it's expecting.