views:

902

answers:

2

Hi all, long time reader/first time poster here.

So I've got a checkbox array that posted just fine to my table when I had an ajax post via:

var createListingString="&features=" + arrayCheckBox;

Now I'm jquerying EVERYTHING (and loving it), but each time I try to post my array with data: $("#create_listing_1").serialize(), I just get "array" in the record it creates (instead of the actual values).

My checkboxes are all formatted:

<input type="checkbox" name="features[]" value="Non-smoking" /> Non-smoking <br />

I'm sure that this is probably an easy one, but I'm making it difficult. AND I wanted to post my first question. Everyone here provides some amazing help, thanks for that.

+1  A: 

You probably need to convert the array to a string first, PHP will give you the string 'Array' if it is converted implicitly. Although I'm not sure how it would have worked before, so apologies if I've completely misunderstood.

$string = implode(', ', $_POST['features']);
Tom Haigh
Yeah, that was all I needed. Thanks a whole lot, Tom! God I love this website.
Adamjstevenson
+1  A: 

I just had this same issue the other day. Here is how I resolved it:

var values = new Array();
$.each($("input[@name='features[]']:checked"), function() {
 values.push($(this).val());
});
var createListingString = values.join();
Knix
You can also use this string as well:`var createListingString = JSON.stringify(values);`
Knix