What's the proper way to get the entire $_POST?

26

7

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.

Spunkie

Posted 2014-04-22T19:02:23.833

Reputation: 682

Retrieving request data using JInput – Dmitry Rekun – 2014-04-22T19:14:41.370

Answers

31

$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.

Harald Leithner

Posted 2014-04-22T19:02:23.833

Reputation: 1 818

2As 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) – George Wilson – 2014-05-12T15:52:25.937

1Often 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 – 2014-04-22T19:20:55.497

3

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.

Spunkie

Posted 2014-04-22T19:02:23.833

Reputation: 682

-3

Hope this will work,

JRequest::get('post');

This will help you to fetch the data from $_POST equivalent in PHP.

goggler

Posted 2014-04-22T19:02:23.833

Reputation: 1

2The question clearly says that this method is deprecated, so OP is looking for the updated method using JInput. – David Fritsch – 2014-05-13T05:23:23.363

@Harald would you mind purging this answer with your special privileges? This user seems to be "long gone". – mickmackusa – 2018-06-19T02:44:46.290