【问题标题】:Post variables in Codeigniter在 Codeigniter 中发布变量
【发布时间】:2013-02-15 12:25:51
【问题描述】:

我在 Codeigniter 中有一个视图,它是一种直接用 HTML 编写的表单。

<form action="http://localhost/index.php/cindice/mostrar" mehtod="post">
<label for="usuario" id="usr">Usuario</label>
<input type="text" name="usuario" /><br /><br />
<label for="contrasenya" id="ctr">Contrase&ntilde;a</label>
<input type="password" name="contrasenya" id="ctr" />
<label for="acceder"></label><br /><br />
<input type="submit" name="acceder" id="bacceder" value="Entrar" /> 
</form>

表单有两个字段:usuario(用户)和 contraseña(密码)。

它是控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cindice extends CI_Controller {


function __construct() {
    parent::__construct();
}

public function index()
{
    $this->load->view('indice');
}

public function mostrar()
{
    $mostrar=$this->input->post('usuario');
    print_r($_POST);
    echo "<br />";

}

 }
?>

当我加载页面 localhost/index/cindice 并输入用户名和密码时。但是print_r($_POST)命令的结果是array(),这意味着表单中保存了任何值。

我该如何解决?

【问题讨论】:

  • 到底是什么问题?是否为 $mostrar 分配了不正确的值?
  • 启动Cpodeigator项目前需要做一些基本配置,请参考文档

标签: codeigniter


【解决方案1】:

我认为它是空的,因为您在开始表单标记中拼写了 method 属性错误。你放了

<form action="http://localhost/index.php/cindice/mostrar" mehtod="post">

应该是什么时候

<form action="http://localhost/index.php/cindice/mostrar" method="post">

【讨论】:

  • 是的。我改变了方法的方法,它起作用了。感谢您的回答。
  • 这是您问题的正确答案,应该这样标记。
【解决方案2】:

请注意,如果您在配置中打开了 CSRF - 如果是,那么您需要使用 codeigniter 表单助手和 form_open() 以便添加隐藏的安全值。

【讨论】:

  • 感谢您的回答。我对CSRF一无所知。我会小心这个的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-20
相关资源
最近更新 更多