我正在尝试使用Dompdf创建PDF,在我的程序中,我根据表单中的输入使用动态参数进行模型查询,但是当我单击我的按钮将值从选择按钮发送到控制器时,数据没有正确发送,任何想法为什么?下面是我的代码
<form class="form" method="get" action="<?=site_url()?>/laporan/pdfdownload" id="myID" name="myName">
<select id="sel1" class="form-control">
<option disabled selected="selected">Pilih</option>
<?php foreach ($kerja as $rows){?>
<option value="<?php echo $rows->id_project?>"><?php echo $rows->id_project.' - '.$rows->nama_project ?></option>
<?php }?>
</select>
<select id="sel2" class="form-control">
<option disabled selected="selected">Pilih</option>
<?php foreach ($item as $rows){?>
<option value="<?php echo $rows->id_project?>"><?php echo $rows->id_project.' - '.$rows->nama_project ?></option>
<?php }?>
</select>
<button id="filter_button" style="margin-top: 26px;margin-left: 28px;width: auto" name="filter_button" type="submit" class="form btn btn-danger"><i class="fa fa-search"></i> Search</button>
</form>
这是我的控制器
public function pdfdownload(){
//If i click submit then all of the post didnt get sended
$one = $this->input->post('sel1');//no value at all, anyone know why?
$two = $this->input->post('sel2');//no value at all, anyone know why?
$data['real'] = $this->report_m($one,$two)->row();
htmlcontent = $this->load->view('laporan/download/laporan3.php',$data,true);
include(APPPATH."third_party/dompdf/autoload.inc.php");
// require_once APPPATH . 'third_party/dompdf/autoload.inc.php';
$dompdf = new Dompdf\Dompdf();
$dompdf->load_html($htmlcontent);
$dompdf->set_paper("f4");
$dompdf->render();
$dompdf->stream("cobadlu.pdf",array("Attachment" => false));
exit(0);
}
enter code here
答案 0 :(得分:1)
在HTML表单中,您需要使用name属性,而不仅仅是ID:
<select id="sel2" name="sel2" class="form-control">
答案 1 :(得分:1)
首先,您的表单中存在错误:
<form class="form" method="get" action="<?=site_url()?>/laporan/pdfdownload" id="myID" name="myName">
您在此处提供 method ='get',请将其更改为'post'。
其次,您没有在输入类型中包含'name'属性,因此在提交后不会发送任何数据。所以添加名称属性:
<select id="sel1" name="sel1" class="form-control">
<select id="sel2" name="sel2" class="form-control">