我使用post方法提交表单但我无法从输入字段获取值。我怎样才能获得价值

时间:2018-04-13 06:41:20

标签: php forms input label codeigniter-3

<form class="form" method="post" action="<?php echo site_url("miner/miner_logins"); ?>">
<label>Email :</label>
<input type="text" name="demail" id="email">
<label>Password :</label>
<input type="password" name="password" id="password"> <br>enter code here
<input type="submit" name="login" id="login" value="LOG IN" class="btnlogin">
<p align="center"><a href="#">Forgot Password? Reset enter code heret via the Website</a></p>
</form>

我的控制器采用codeignite代码

3 个答案:

答案 0 :(得分:2)

您可以更新表单以保留输入值,请仔细查看set_value部分,有关详细信息,请访问HERE

<form class="form" method="post" action="<?php echo site_url("miner/miner_logins"); ?>">
<label>Email :</label>
<input type="text" name="demail" value="<?php echo set_value('demail'); ?> id="email">
<label>Password :</label>
<input type="password" name="password" id="password"> <br>enter code here
<input type="submit" name="login" id="login" value="LOG IN" class="btnlogin">
<p align="center"><a href="#">Forgot Password? Reset enter code heret via the Website</a></p>
</form>

miner.php文件内写下方法miner_logins

public function miner_logins(){
  $this->load->library('form_validation');
  $this->form_validation->set_rules('password', 'Password', 'required');
  $this->form_validation->set_rules('demail', 'Email', 'required|valid_email');

  if ($this->form_validation->run() == FALSE)
  {
     $this->load->view('miner_logins_view');
  }else{
    // set required session here and do redirection to user page.
  }
}

我还没有对代码进行过测试,但希望这可以帮助您了解如何在CI中处理表单提交。

答案 1 :(得分:0)

在您班级的miner_logins miner中,您可以获得如下所示的值,这可能会对您有所帮助。 总是尝试通过创建变量来分配它,以获得更好的代码结构。

if($this->input->post())   // Before getting the values, check with this
{
    $demail   = $this->input->post('demail', TRUE);
    $password = $this->input->post('password', TRUE);

    echo $demail; // You will get the value of demail.
    echo $password; // You will get the value of password.
}

答案 2 :(得分:0)

试试这个

$var_1 = $this->input->post('demail', TRUE);
$var_2 = $this->input->post('password', TRUE);