Retrieving unfiltered input in Joomla 2.5+

While Joomla 2.5+ provides a neat way of retrieving filtered input, working with unfiltered input is not as straight forward.

Retrieving input in Joomla 2.5+ is done by using JInput.

We can access the JInput object like this:


If we are retrieving more values, it would be useful to store the JInput object in a variable so we don’t need to call JFactory::getApplication() every time we are doing that:

$jinput = JFactory::getApplication()->input;

To retrieve a value from JInput we need to use its get method:

$foo = $jinput->get('varname', 'default_value', 'filter');

As you can see, it has 3 parameters:

  1. the variable name
  2. the default value (defaults to null)
  3. the filter name (defaults to cmd)
You can write, for example, $jinput->getInt(‘varname’, ‘default_value’) instead of $jinput->get(‘varname’, ‘default_value’, ‘filter’)

While there are many filters, none of them leave the values untouched. Except for the array filter. So we can use that to retrieve unfiltered input:

list($unfiltered_foo) = $jinput->get( 'varname', array(0), 'array' );

You might say “Ok, but my value is not an array!”.. Not to worry! JInput will take the value and convert it into an one element array. It’s also a good practice to specify an one element array, usually containg 0, as a default value, just in case the varname is not found, otherwise, JInput->get() will return null and list($unfiltered_foo) will fail, throwing an error.

Another way of retrieving unfiltered content is by creating a permissive filter and a JInput using that filter:

$filter = JFilterInput::getInstance( array(), array(), 1, 1, 0 );
$jinput = new JInput( null, array('filter' => $filter) );
$foo = $jinput->get('varname', 'default_value', 'none');

Notice we have specified ‘none’ as our filter. You can write anything you want, as long as that filter does not exist, otherwise Joomla will still use its default filters.

You can view their documentation by accessing the following links:

I hope you found my little tutorial useful.

Stay tuned for more!

  1. Thank you for posting this! I had look everywhere…

  2. You’re welcome :) I’m glad it helped you.

  3. Joomla STILL hasn’t resolved this issue as of the latest version of 2.5. Your fix works perfectly. Thanks again!

  4. Hey Brat. I’m glad this fix helped you!

Leave a Reply