控制器没有在codeigniter中获得输入值

时间:2016-01-13 17:26:47

标签: php codeigniter post controller codeigniter-2

我有一个输入字段

    <?php
    echo form_open('moneyexchange/borrow_first_page');  ?>
    <input id ="Amount" type="text" placeholder="Amount in &euro;"  name="writtenamount">
 <a type="submit" href="<?php echo base_url();?    >index.php/moneyexchange/invest_first_page">invest</a>
              </form>

在codeigniter moneyexchange控制器中我有一个功能

public function invest_first_page(){
        $this->load->helper('form');
         $this->load->library('form_validation');
        $this->load->view('header');

        $userProvidedAmount = $this->input->post("writtenamount");
        $data =  array(
        'userProvidedAmount' => $userProvidedAmount
         );
        $this->load->view("invest_firstpage", $data);
        $this->load->view('footer');

    }

但由于某种原因,我无法从视图文件中的输入字段获取值到控制器,请帮忙。 它表明我的$ userPRovidedAmount是一个(bool)false值。但我需要从输入变量中获取数字 enter image description here

1 个答案:

答案 0 :(得分:1)

您有一个提交按钮的链接。链接不会提交表单(除非有一些看不见的javascript) - 它只会向页面发出常规GET请求(因此控制器中POST为空的原因)

更改表单的操作,并将提交按钮设为表单元素:

<?php echo form_open('moneyexchange/invest_first_page');  ?>
    <input id ="Amount" type="text" placeholder="Amount in &euro;"  name="writtenamount"/>
    <input type="submit" value="invest"/>
<?php echo form_close();?>