【问题标题】:I am submitting form by using post method but i am unable to get the value from input field. How I can get the value我正在使用 post 方法提交表单,但我无法从输入字段中获取值。我如何获得价值
【发布时间】:2018-04-13 06:41:20
【问题描述】:
<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 代码中的控制器

【问题讨论】:

  • 在你的控制器方法miner_logins尝试` echo $this->input->post('demail', TRUE);死;`
  • 我希望他们有手册
  • @AlivetoDie 我刚刚发布了答案,您可以看到我的评论和答案之间的区别。

标签: php forms input label codeigniter-3


【解决方案1】:

您可以更新表单以保留输入值,请仔细查看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 中处理表单提交。

【讨论】:

    【解决方案2】:

    试试这个

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

    【讨论】:

      【解决方案3】:

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

      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.
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-20
        • 2012-02-11
        • 1970-01-01
        相关资源
        最近更新 更多