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...
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.
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.
尝试这个
$post = JFactory::getApplication()->input->post;
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);
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.