Hello I have a problem using codeigniter. Here I want to save the data selected through the dropdown into a session, then display the selected data to a page called step4. I have tried but when I display the data, it does not appear.
Here is the script:
Controller Step1.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Step1 extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('session');
$this->load->model('M_datasiswa');
}
public function step1()
{
$data['departemen'] = $this->M_datasiswa->get_departemen();
$data['tahunajaran'] = $this->M_datasiswa->get_tahunajaran();
$this->load->view('v_step1',$data);
}
function save_data(){
$depart = $this->input->post('kode_departemen');
$tahun = $this->input->post('kode_tahun');
$asal = $this->input->post('kode_asal');
$data = array(
'departemen' => $depart,
'proses' => $tahun,
'asal' => $asal
);
$this->session->set_userdata($data);
redirect('step4');
}
}
v_step1.php
<form action="<?php echo base_url('Step1/save_data'); ?>" method="post">
<table border="0" style="text-align:left; margin-left: auto; margin-right: auto; width:97%; margin-top:50px;">
<tr style="height:50px;">
<td style="width:100px;"> </td>
<td class="tulisanDalamTabel" colspan="2"> Departemen </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_departemen" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH UNIT--</option>
<?php
foreach ($departemen as $row) { echo "<option value='".$row->replid."'>".$row->departemen."</option>";}echo"</select>"?>
</td>
</tr>
<tr style="height:50px;" >
<td style="width:100px;"></td>
<td class="tulisanDalamTabel" colspan="2"> PPDB </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_tahun" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH TAHUN AJARAN--</option>
<?php
foreach ($tahunajaran as $row) { echo "<option value='".$row->replid."'>".$row->proses."</option>";}echo"</select>"?>
</td>
</tr>
<tr style="height:50px;">
<td style="width:100px;"></td>
<td class="tulisanDalamTabel" colspan="2"> Asal Calon Siswa </td>
<td colspan="1" style="width: 100px;"> </td>
<td colspan="2">
<select required name="kode_asal" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;">
<option value="" disabled diselected>--PILIH--</option>
<option> UMUM </option>
<option> KELUARGA YAYASAN </option>
</td>
</tr>
<tr style="height:50px;">
<td colspan="8"><hr style="width: 98%"/></td>
</tr>
<tr style="height:50px;">
<td class="tulisanDalamTabel" colspan="2"><input type="submit" class="buttonKembali" value="Batal Daftar" style="vertical-align:middle"> </td>
<td colspan="4"> </td>
<td class="tulisanDalamTabel" style="text-align:right; width:380px"><input type="submit" class="buttonSelanjutnya" value="Selanjutnya" style="vertical-align:middle;"> </td>
</tr>
</table>
</form>
v_step4.php
<table border="1" style="text-align:left; margin-left: auto; margin-right: auto; width:97%; margin-top:50px;">
<tr style="height:50px;">
<td class="tulisanDalamTabel"> Nama Lengkap </td>
<td> <input type="text" placeholder="Nama Lengkap" class="tulisanDalamTabel" style="width:98%; margin-left: 7px; height:40px;"/> </td>
<td> <?php $this->session->userdata('departemen') ?></td>
<td class="tulisanDalamTabel"> Nama Panggilan </td>
<td> <input type="text" placeholder="Nama Panggilan" class="tulisanDalamTabel" style="width:97%; margin-left: 1px; height:40px;"/> </td>
</tr>
Thanks, hope someone can help me.
CodePudding user response:
You forgot to print using echo
<td> <?php $this->session->userdata('departemen') ?></td>
Do this instead
<td> <?php echo $this->session->userdata('departemen') ?></td>