使用CodeIgniter在同一页面上打印表单的结果

时间:2015-08-13 17:24:40

标签: php html forms codeigniter web

我有这个注册码:

一个。控制器



<?php  
 class Manual extends CI_Controller {  
      public function __construct(){  
           parent::__construct();  
           $this->load->model("model_manual");  
      }       
      public function index(){  
      $this->insert();       
      }  
      public function insert()  
      {  
           $this->form_validation->set_rules('nama', 'Nama', 'required');  
		   $this->form_validation->set_rules('npm', 'Npm', 'required');
           $this->form_validation->set_rules('matkul','Matkul','required');  
           if ($this->form_validation->run())  
           {       
           $register=$this->model_manual->insertdata($_POST);  
           if($register){  
                     echo "<script>alert('Input Sucessfully')</script>";  
					 }  
           }  
           $data['title']="Input data";  
		$data=array('isi'  	=>'home/manual_view');
		$this->load->view('layout/wrapper',$data);       
      }  
 }  
 ?>  
&#13;
&#13;
&#13;

湾模型

&#13;
&#13;
<?php  
 class Model_manual extends CI_Model {  
		function insertdata($options = array()){  
           if(isset($options['nama']))  
                $this->db->set('nama',strip_tags($options['nama']));  
           if(isset($options['npm']))  
                $this->db->set('npm',strip_tags($options['npm']));			
           if(isset($options['matkul']))  
                $this->db->set('matkul',($options['matkul']));  
                $this->db->insert("tabel_manual");  
           return $this->db->insert_id();  
		}  
	  
		function cek_user($data) {
			$query = $this->db->get_where('tabel_manual', $data);
			return $query;
		}
		
		function getAllUser() {
		$this->db->from('tabel_manual');
		return $this->db->get();
		}
		
 }  
 ?>  
&#13;
&#13;
&#13;

℃。图

&#13;
&#13;
<div class = "well" style = "background-color :lavender;">

<button class="btn btn-default" style= "padding-top : 9px; padding-bottom : 9px;"><a href = "<?php echo base_url(); ?>home" style = "text-decoration : none;"><span class="glyphicon glyphicon-home"></span></a></button>
<button class="btn btn-default"><a href = "<?php echo base_url(); ?>blanko" style = "text-decoration : none;"><span class="glyphicon glyphicon-list-alt"></span> Blanko</a></button>

<div class = "row">
<div class = "col-sm-offset-3 col-sm-6" style = "text-align : center">
<label style = "font-size: 20px;">INPUT DATA</label>
</div>

<div class = "row">
<div class = "col-sm-offset-4 col-sm-4">
<form class="form-horizontal" action="" method="post" style = "margin : 10px;">
		
		<div class="form-group">
		<label style = "font-family : cambria;">Nomor Pokok Mahasiswa :</label>
		<input style = "font-family : cambria;" type="text" class="form-control" placeholder = "Typehere"
		name="npm" id="npm"/>
		<font color="#FF0000"><?php echo form_error('npm');?></font>
		</div>
		
		<div class="form-group">
		<label style = "font-family : cambria;">Nama Lengkap :</label>
		<input style = "font-family : cambria;" type="text" class="form-control" placeholder = "Typehere"
		name="nama" id="nama"/>
		<font color="#FF0000"><?php echo form_error('nama');?></font>
		</div>
				
		<div class="form-group">	
		<label style = "font-family : cambria;">Mata Ujian :</label>
		<select class="form-control" name="matkul" id="matkul">
		<option value="">Select</option> 
		<option value="pancasila">Pancasila</option>  
		<option value="matdas2">Matematika Dasar 2</option>
		<option value="ap2">Algo.Pemograman 2</option>
		<option value="ap3">Algo.Pemograman 3</option>
		<option value="matif4">Matematika Informatika 4</option>
		<option value="sisber">Sistem Berkas</option>
		<option value="arkom">Arsitektur Komputer</option>
		<option value="jarkom">Jaringan Komputer</option>
		<option value="si">Sistem Informasi</option>
		<option value="so">Sistem Operasi</option>
		<option value="imk">IMK</option>
		<option value="sbd2">SBD 2</option>
		<option value="tbo">TBO</option>
		<option value="rpl2">RPL 2</option>
		</select> 
		<font color="#FF0000"><?php echo form_error('matkul');?></font>
		</div>
		
		<br>
		<div class="form-group">	
        <button type="submit" class="btn btn-default" style = "font-family : cambria; ">Input</a></button>
		<button type="reset" class="btn btn-default" style = "font-family : cambria;">Reset</button>
		</div>
	</div>
	</div>
	</form>
	
 </div>
 </div>
&#13;
&#13;
&#13;

对于视图,我使用bootstrap来设计我的界面。 问题是......如何从表格中打印出结果我去了&#34;点击&#34;同一页面中的提交按钮?

我只是想制作表格,然后在那个表格下面,我可以显示结果。

1 个答案:

答案 0 :(得分:-1)

@ariyanti你提交表单时必须使用session,然后在插入时你需要设置表单数据的会话,然后你可以使用session打印你的表单发布数据,我有一个简单的表单提交方式你在codeigniter中的代码如果你同意那么我会帮助你..