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:
- the variable name
- the default value (defaults to null)
- the filter name (defaults to cmd)
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!