问题
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...
回答1:
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.
回答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.
回答3:
Try this
$post = JFactory::getApplication()->input->post;
回答4:
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);
回答5:
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
来源:https://stackoverflow.com/questions/21476081/get-dynamic-post-fields-data-via-jinput-in-joomla