简体   繁体   English

通过Joomla中的JInput获取动态发布字段/数据

[英]Get Dynamic Post Fields/Data via JInput in Joomla

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). 基本上如问题所述,我需要在Joomla 2.5 / 3.xx中获取“ POST”数据,并且希望通过JInput(该镇的新话题)获得它。

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... 它(字段)旨在根据情况进行更改,我无法知道字段将是什么,我知道如何在核心php中进行操作,但JInput并非如此,因此,如何我会做...

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. 好吧,我知道这是被问到已经有一段时间了,但是今天我遇到了这个问题,找到了一个Joomla解决方案,用于POST表单。

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

This is essentially the same as using $fieldname = $_POST['fieldname']; 这本质上与使用$fieldname = $_POST['fieldname']; except you get the added benefit of staying within Joomla's API. 除了获得使用Joomla API的额外好处。

JInput doesn't offer such feature; JInput不提供这种功能。 so you might have to use $_POST. 因此您可能必须使用$ _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()) ) 如果可以将输入采用数组形式(并使用JInput::getArray() )或json编码的对象(您使用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: Joomla3提供两个功能:

JInputJSON (extends Jinput with the getRaw() method) JInputJSON (使用getRaw()方法扩展Jinput)

JResponseJson (convert and return data as JSON) JResponseJson (将数据转换为JSON并返回)

The request data: 请求数据:

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

Joomla: 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

$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 : //docs.joomla.org/Retrieving_request_data_using_JInput

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM