>我在获取文本框的值并将其传输到控制器时遇到问题
这是我的代码
清单.php(查看(
<form method="POST" action="<?php echo base_url('PortClient/view_voyage/');?>">
<div class=" container">
<div class="row">
<?php foreach($voyage_info as $voyage) { ?>
<input type="hidden" name="voyage_id" value="<?=$voyage->voyage_id?>">
</form>
<button type="submit" class="btn btn-primary primary-bg btn-lg col-md-2 m-3 btn-cus">
<h3>Voyage - <?=$voyage->voyage_number?></h3>
<small>Schedule - <?=$voyage->expected_arrival?> </small>
</button>
<?php } ?>
我想获取voyage_id并将其传输到控制器
端口客户端.php(控制器(
public function view_voyage() {
$this->Auth->authCheck();
$data = $this->template();
$voyage_id = $this->input->post('voyage_id');
$data['view_cargo'] = $this->PortManifestModel->view_voyage($voyage_id)->result();
// your code here
$this->load->view("port/client/sub_manifest/sub_manifest_1", $data);
}
文本框voyage_id值不会转移
我该怎么办?
首先,在按钮中添加名称。
<button type="submit" name="submit">Submit button</button>
修改控制器
public function view_voyage() {
$this->Auth->authCheck();
$data = $this->template();
if($_POST["submit"]){
$voyage_id = $this->input->post('voyage_id');
$data['view_cargo'] = $this->PortManifestModel->view_voyage($voyage_id)->result();
}
$this->load->view("port/client/sub_manifest/sub_manifest_1", $data);
}
试试这个...
请在表单中添加您的提交按钮。
目前按钮放在表单之后,您应该将其添加到表单中。
而且您还有正确的 for 循环。