我有一个输入字段
<?php
echo form_open('moneyexchange/borrow_first_page'); ?>
<input id ="Amount" type="text" placeholder="Amount in €" 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值。但我需要从输入变量中获取数字
答案 0 :(得分:1)
您有一个提交按钮的链接。链接不会提交表单(除非有一些看不见的javascript) - 它只会向页面发出常规GET
请求(因此控制器中POST
为空的原因)
更改表单的操作,并将提交按钮设为表单元素:
<?php echo form_open('moneyexchange/invest_first_page'); ?>
<input id ="Amount" type="text" placeholder="Amount in €" name="writtenamount"/>
<input type="submit" value="invest"/>
<?php echo form_close();?>