I am sending a POST ajax call like this:
var request = {
option : 'com_ajax',
module : 'mod_test', // to target: mod_test
method : 'Test', // to target: function TestAjax in class modTestHelper
format : 'raw',
data : {a: [], b: {}, c: [0], d: [null]}
};
$.ajax({method: 'POST', data: request})
// .success( ...yatta yatta
I am receiving with:
$data = JFactory::getApplication()->input->post->get('data', array(), 'array');
However, the passed empty subarray (a
) and subobject (b
) are purged before reaching my php script. So, the contents of $data
is ['c'=>'0', 'd'=>['']]
. In other words, when I call isset($data['a'])
or isset($data['b'])
they evaluate as false
.
For my module, I ended up passing the string 0
to represent an empty array, but my code would be tidier if I was permitted to pass an empty array to php. (For my project, the first level has a known number of elements, only the subarrays are dynamically generated.)
- Is this a bug, a feature, and/or a known behavior?
- Am I able to adjust my
JFactory...
line to accept empty subarrays?
I did get some insight but not a complete solution from these related answers:
- https://joomla.stackexchange.com/a/4233/12352
- https://joomla.stackexchange.com/a/5344/12352
- https://joomla.stackexchange.com/a/17659/12352
- https://joomla.stackexchange.com/a/4558/12352
I am using Joomla 3.8.6