In Joomla! 2.5.x I could simply run JRequest::get('post'); but seeing as JRequest is deprecated in Joomla! 3.x I should use JInput.

At them moment this is the code I'm using to get the entire $_POST:

$app = JFactory::getApplication();
$postData = $app->input->getArray(array_flip(array_keys($_POST)));

But this seems rather cumbersome and I run into issues if used in conjunction with $app->input->set(); I would think there would be a better way?

When searching for this before I've found people saying you can simply run

$app = JFactory::getApplication();
$postData = $app->input->post;

But when I tried this out I simply got an instance of the JInput object.


2 Answers 2

$app = JFactory::getApplication();
$postData = $app->input->post;

Is the way to go, you will get a JInput object and can use it like JRequest

$var = $postData->get('varname', 'defaultvalue', 'filter');

The filter could be 'int', 'cmd' or many others - the complete list can be found in this function: https://github.com/joomla/joomla-cms/blob/a3df15f1ddad6d9051d53f939b6afd2f5fca60b7/libraries/joomla/filter/input.php#L138

If you would only like the array, then you can do

$array = $app->input->post->getArray();

But you should avoid this style of accessing user-data without filtering.

  • 1
    Often times I need to get the entire $_POST without actually knowing the names of the vars I need to get, that is why using the JInput object like that is not useful in many cases. Still a good answer though.
    – Spunkie
    Commented Apr 22, 2014 at 19:20
  • 2
    As an FYI The $app->input->post->getArray(); is only valid on Joomla 3.2.0 and later. And in any earlier version (including 2.5) you have to use $app->input->getArray($_POST) Commented May 12, 2014 at 15:52

It seems another way to accomplish this is simply pass an empty array:

$app = JFactory::getApplication();
$postData = $app->input->getArray(array());

This will retrieve everything in the JInput data var as if you were accessing the $_REQUEST super.

This does not work in the Joomla! 2.5.x version of JInput though.

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