26

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.

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.

  • 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 Apr 22 '14 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) – George Wilson May 12 '14 at 15:52
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.

-3

Hope this will work,

JRequest::get('post');

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

  • 2
    The question clearly says that this method is deprecated, so OP is looking for the updated method using JInput. – David Fritsch May 13 '14 at 5:23
  • @Harald would you mind purging this answer with your special privileges? This user seems to be "long gone". – mickmackusa Jun 19 '18 at 2:44

protected by Lodder Jan 31 '15 at 14:48

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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