Get Dynamic Post Fields/Data via JInput in Joomla
Asked Answered
M

5

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

Maimonides answered 31/1, 2014 at 9:9 Comment(0)
U
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.

Unbolt answered 13/9, 2014 at 15:3 Comment(0)
E
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.

Eau answered 31/1, 2014 at 9:25 Comment(3)
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.Maimonides
If they do, they're wrong. Just kidding. But you could use the serializeArray() in jQuery and JInput::getArray() on the server.Eau
I just used the Global POST, So I Got That Goin’ For Me, Which is Nice, Until they start offering this feature.Maimonides
L
1

Try this

    $post = JFactory::getApplication()->input->post;
Linchpin answered 21/5, 2014 at 12:20 Comment(0)
W
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);
Wellestablished answered 16/6, 2016 at 9:25 Comment(0)
H
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

Hallock answered 28/11, 2018 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.