Skip to content
Advertisement

Post array with Ajax but PHP gets string

I’m posting several variables from Ajax to PHP and one of them is an array. However PHP sees a string instead of an array. I can’t figure out what’s wrong.

Ajax string seen in Firefox Dev console:

Form data:

id=106
category_name=windows
category_friendly_name=Windows+product
show_for_ids=4
show_for_ids=7
show_for_ids=10
show_for_ids=12
is_admin_only=0
action=edit

Request payload

id=106&category_name=windows&category_friendly_name=Windows+product&show_for_ids=4&show_for_ids=7&show_for_ids=10&show_for_ids=12&is_admin_only=0&action=edit

PHP:

var_dump($_POST['show_for_ids']);

Outputs:

string(2) "12"

Using Multi-select plugin for TableEdit and Jquery-multi-select

What am I missing?

Advertisement

Answer

Thanks to @u_mulder comment I fixed the issue by modifying the code provided on Github for jquery-tabledit line 140.

I changed

input = '<select class="multiSelect tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '" style="display: none; width:auto;" disabled multiple >';

Into

var input = '<select class="multiSelect tabledit-input ' + settings.inputClass + '" name="' + settings.columns.editable[i][1] + '[]" style="display: none; width:auto;" disabled multiple >';
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement