4

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.

2 Answers 2

3

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();
Sign up to request clarification or add additional context in comments.

1 Comment

You can also use this string as well: var createListingString = JSON.stringify(values);
2

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']);

1 Comment

Yeah, that was all I needed. Thanks a whole lot, Tom! God I love this website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.