2

Maybe it's weary eyes, but I am unable to retrieve a posted array from jInput:

$jinput = JFactory::getApplication()->input;
$test1 = $jinput->get('Itemid');
$test2 = $jinput->get("filter");
$test3 = $jinput->get("filter['subjects']");

$test1 successfully retrieves the Itemid, but various ways of retrieving 'filter' only ever results in an empty array.

JInput Object
(
    [options:protected] => Array
        (
        )

    [filter:protected] => JFilterInput Object
        (
            [tagsArray] => Array
                (
                )

            [attrArray] => Array
                (
                )
        )
    [data:protected] => Array
        (
            [option] => com_xyz
            [view] => titles
            [Itemid] => 241
            [filter] => Array
                (
                    [subjects] => Array
                        (
                            [0] => 6
                        )
                )
            [limit] => 25
            [limitstart] => 0

I don't mind feeling stupid for an oversight at this point, I'm just tired of fighting with it. Any assistance is appreciated. :)

1

3 Answers 3

3

Try this:

$app        = JFactory::getApplication();
$jinput     = $app->input;
$filter     = $jinput->getVar('filter',array());

Hope it works for you

1
  • "Try this" answers on StackExchange sites are low value because they do very little to educate future researchers. If you are able to expand on your answer to explain how your snippet works and why it is recommended, then please do so. If it is too basic to describe, perhaps offer some resource/documentation links which spell things out. Please always post answers with the intent to educate. Commented Apr 6, 2018 at 2:24
3

I misread or misunderstood the documentation of $jinput->getArray(). I understood this to return a subset of the input variables, as specified in an array of the variables you're interested in. While this may be true, it will also return all input variable if an empty array is supplied:

$allfields = $jinput->getArray(array())
3
  • 1
    The answer doesn't address the actual problem of OP. OP wants to get a posted array not array of all posted variables. Your answer fetches the latter.
    – Ejaz
    Commented Dec 15, 2015 at 12:05
  • 1
    As the OP, I have to differ - I added this answer a courtesy of what I actually used to get what I described in the question.
    – GDP
    Commented Dec 15, 2015 at 16:51
  • 1
    I totally missed the fact that you were the OP, isn't that comedy :D
    – Ejaz
    Commented Dec 15, 2015 at 18:13
2

Just been messing around with this a little.

Try adding a blank default value and filter type as arguments, like so:

$test2 = $jinput->get('filter', '', 'RAW');
3
  • 1
    This worked as well, but Piero beat you by 2 hours - no flowers for you this time, lol.
    – GDP
    Commented Sep 18, 2015 at 13:03
  • Pfff, any excuse not to get flowers lol
    – Lodder
    Commented Sep 18, 2015 at 13:04
  • Don't worry, you'll get another chance....I have a new question coming shortly, lol
    – GDP
    Commented Sep 18, 2015 at 13:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.