繁体   English   中英

使用Joomla 2.5获得$ _POST

[英]Getting $_POST with Joomla 2.5

这是我的表格,它看起来是正确的,所以这不是一个问题,我也删除了enctype以确保它不是那个。

    <form action="<?php echo JRoute::_('index.php?option=com_woo&task=hello.create'); ?>" enctype="multipart/form-data" method="post">
      <p>
        Project Name : 
        <input style="width:30%;" name="name" id="name"/>
        <input style="display:none;" id="user_id" name="user_id" value="<?php echo $user->id;?>"/>
        <input style="display:none;" id="county" name="county"/>
        <input style="display:none;" id="state" name="state"  />
      </p>
      <button type="submit" class="btn-green" id="select_county">Create Project</button>
    </form>

在ControllerHello里面

    public function create()
    {
       $jinput = JFactory::getApplication()->input;
       $foo = $jinput->get('state', '', 'filter');
       print_r($foo);
       die;
    }

返回“NULL”

有任何想法吗?

你可以尝试这个 -

$input = JFactory::getApplication()->input;
$post_array = $input->getArray($_POST);
$input = new JInput;
$name = $input->get('name', '', 'post');
$country = $input->get('country', '', 'post');
// etc.

然后,您可以使用一系列JInput类方法用于特定目的:

 // method      integer  getInt()       getInt($name, $default = null)    Get a signed integer.
 // method      integer  getUint()      getUint($name, $default = null)   Get an unsigned integer.
 // method      float    getFloat()     getFloat($name, $default = null)  Get a floating-point number.
 // method      boolean  getBool()      getBool($name, $default = null)   Get a boolean.
 // method      string   getWord()      getWord($name, $default = null)
 // method      string   getAlnum()     getAlnum($name, $default = null)
 // method      string   getCmd()       getCmd($name, $default = null)
 // method      string   getBase64()    getBase64($name, $default = null)
 // method      string   getString()    getString($name, $default = null)
 // method      string   getHtml()      getHtml($name, $default = null)
 // method      string   getPath()      getPath($name, $default = null)
 // method      string   getUsername()  getUsername($name, $default = null)

我认为使用JInput获得整个$ _POST的最佳选择是

JFactory::getApplication()->input->post->getArray();

如果要从请求中获取特定数组(例如,称为“jform”),请使用

JFactory::getApplication()->input->get('jform', array(), 'ARRAY');

您可以从特定超级全球获取价值

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

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

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

有关更多信息,请转至使用JInput检索请求数据

您可以尝试将表单操作更改为:

<?php echo JRoute::_('index.php?option=com_woo&view=hello&task=create');

由于你的任务被称为create not hello.create,它可能会更好地工作....

然后我总是这样做

$post = JRequest::get('post');
print_r($post['state']);

暂无
暂无

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

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