Joomla get POST data from form using jinput

Posted In: blog |

As from Joomla! 1.5 retrieving POST data through JRequest::getVar('var_name'); or JRequest::get('post'); is deprecated. The new approach to get the whole $_POST array :

Retrieving single value from $_POST:

The Jinput class provides the capability of filtering data. Avaible filters are:

  • INT, INTEGER – Matches the first, signed integer value.
  • UINT – Matches the first unsigned integer value.
  • FLOAT, DOUBLE – Matches the first floating point number.
  • BOOL, BOOLEAN – Converts the value to a boolean data type.
  • WORD – Allows only case insensitive A-Z and underscores.
  • ALNUM – Allows only case insensitive A-Z and digits.
  • CMD – Allows only case insensitive A-Z, underscores, periods and dashes.
  • BASE64 – Allows only case insensitive A-Z, forward slash, plus and equals.
  • STRING – Returns a fully decoded string.
  • HTML – Returns a string with HTML entities and tags intact, subject to the white or black lists in the filter.
  • ARRAY – Returns the source as an array with no additional filtering applied.
  • PATH – Matches legal characters for a path.
  • USERNAME – Strips a select set of characters from the source (\x00, -, \x1F, \x7F, <, >, “, ‘, %, &).

There are two basic ways of using filters, for example:

and

Above examples have the same effect. In the $id we get an id from the request ensuring, that it is an integer.

As an bonus here is an example of parsing form fields wrapped in the jform array.

This one was found on phproberto.com

More on Jinput Class could be found in Joomla documentation or in this Joomla manual.

When working on custom components You’ll probably like the below snippet:

Stealed it from here: https://snipt.net/raw/7bae96ea4a6a97920f4aecbcd0f29308/?nice


Post Tags: joomla | php |


Comments Off on Joomla get POST data from form using jinput