1

Basically as the question describes, I need to get "POST" data in Joomla 2.5/3.xx and I want it through the JInput (the new talk of the town).

Now everything is fine and dandy, until my further requirements needs those fields/data to be dynamic, ie. It(the fields) is designed to change depending on circumstances,there's no way for me to know what the fields are gonna be, I know how to do it in core php, but that's not the case with JInput, so thats it, how do I do it...

Mohd Abdul Mujib
  • 13,071
  • 8
  • 64
  • 88

5 Answers5

3

Well I know this has been some time since this was asked, but I came across the issue today and found a Joomla solution for POST forms.

$input = JFactory::getApplication()->input;
$fieldname = $input->post->get('fieldname');

This is essentially the same as using $fieldname = $_POST['fieldname']; except you get the added benefit of staying within Joomla's API.

Ruslanas Balčiūnas
  • 7,310
  • 3
  • 24
  • 41
codacopia
  • 2,369
  • 9
  • 39
  • 58
2

JInput doesn't offer such feature; so you might have to use $_POST.

You could get around it if you can have the input be in the form of array (and use JInput::getArray() ) or a json-encoded object (you use json_decode(JInput::getString()))

The latter is very effective I have used it with success on many projects.

Riccardo Zorn
  • 5,590
  • 1
  • 20
  • 36
  • so atm, I am using the .serialize() function in Jquery directly serializing the whole form and submitting via ajax, you mean to say, that I first get the whole of the data in an object and then json encode the object and pass it, if its the case then it seems a bit awkward to me, Lets see if anyone's got a different view/opinion. – Mohd Abdul Mujib Jan 31 '14 at 09:32
  • 1
    If they do, they're wrong. Just kidding. But you could use the serializeArray() in jQuery and JInput::getArray() on the server. – Riccardo Zorn Jan 31 '14 at 14:24
  • I just used the Global POST, So I Got That Goin’ For Me, Which is Nice, Until they start offering this feature. – Mohd Abdul Mujib Feb 01 '14 at 07:24
1

Try this

    $post = JFactory::getApplication()->input->post;
Ruslanas Balčiūnas
  • 7,310
  • 3
  • 24
  • 41
Stergios Zg.
  • 652
  • 6
  • 9
1

Joomla3 offers two functions:

JInputJSON (extends Jinput with the getRaw() method)

JResponseJson (convert and return data as JSON)

The request data:

var jsonString = '{"test":"1"}';
var data = { ajaxrequest : jsonString }

Joomla:

$jinput = JFactory::getApplication()->input;
$json = $jinput->getRaw('ajaxrequest'); // returns {\"test\":\"1\"}
$data = json_decode($json); // json decode, returns data object

// do stuff..

echo new JResponseJson($response);
Dennis Heiden
  • 757
  • 8
  • 16
1

You can use Jinput for this

$jinput = JFactory::getApplication()->input;

Getting Values from a Specific Super Global

$foo = $jinput->get->get('varname', 'default_value', 'filter');
$foo = $jinput->post->get('varname', 'default_value', 'filter');
$foo = $jinput->server->get('varname', 'default_value', 'filter');

Please refer this document for more details: https://docs.joomla.org/Retrieving_request_data_using_JInput

Daniel Larsson
  • 527
  • 2
  • 6
  • 23
Vijay Khollam
  • 21
  • 1
  • 6