update in codeigniter 3, it's run but database didnt changed - codeigniter-3

i dont understand with my code. it's run, and work. but when i see in database didnt changed.
here's my controller, function perbarui for get id data, get the data id from model (MMobil).
public function perbarui($id = NULL){
$this->load->model('merek');
$this->load->library('form_validation');
$data['merk'] = $this->merek->getList();
$data['detail'] = $this->MMobil->detail($id);
$submit = $this->input->post('submit');
print_r($data);
if ($submit) {
$nomor_kendaraan = $this->input->post('nomor_kendaraan');
$nomor_mesin = $this->input->post('nomor_mesin');
$id_merek = $this->input->post('id_merek');
$tahun_beli = $this->input->post('tahun_beli');
$nama_mobil = $this->input->post('nama_mobil');
$this->form_validation->set_rules('nama_mobil', 'Nama_Mobil', 'required');
$this->form_validation->set_rules('nomor_kendaraan', 'Nomor_Kendaraan', 'required');
$data['detik'] = $this->MMobil->setData($nomor_kendaraan, $nomor_mesin, $id_merek, $tahun_beli, $nama_mobil);
if ($this->form_validation->run() == FALSE) {
$data['errors'] = TRUE;
}else{
$data['detail'] = $this->MMobil->detail($id);
print_r($data);
}
//redirect('Master');
}
$this->load->view('master-detail-mobil', $data);
}
here's my models. function setData for storage variable after click submit. function edit get id data and get variable arrayData from function setData
public function setData($nomor_kendaraan, $nomor_mesin, $id_merek, $tahun_beli, $nama_mobil){
$this->nomor_kendaraan = $nomor_kendaraan;
$this->nomor_mesin = $nomor_mesin;
$this->id_merek = $id_merek;
$this->tahun_beli = $tahun_beli;
$this->nama_mobil = $nama_mobil;
}
public function edit($id){
$arrayData = array(
'nomor_kendaraan' => $this->nomor_kendaraan,
'nomor_mesin' => $this->nomor_mesin,
'id_merek' => $this->id_merek,
'tahun_beli' => $this->tahun_beli,
'nama_mobil' => $this->nama_mobil,
);
$this->db->where('nomor_mesin', $id);
return $this->db->update($this->table,$arrayData);
}
here's my views
<?php $this->load->view('header.php'); ?>
<?php
echo"<h4>UPDATE DATA</h4>";
?>
<form class="form-horizontal" role="form" method="post" action="<?php echo site_url()?>/Master/perbarui/">
<div class="form-group">
<label class="control-label col-sm-2" for="noken">Nomor Kendaraan :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nomor_kendaraan" value="<?php
echo #$detail->nomor_kendaraan;
?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="nomes">Nomor Mesin :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nomor_mesin" value="<?php
echo #$detail->nomor_mesin;
?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="merk">Merek Mobil :</label>
<div class="col-sm-10">
<select class="form-control" name="id_merek">
<?php foreach ($merk as $mrk) :?>
<option value="<?php echo $mrk->id_merek ?>">
<?php
echo $mrk->nama_merek;
?>
</option>
<?php endforeach?>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="thn">Tahun Beli :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="tahun_beli" value="<?php
echo #$detail->tahun_beli; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="namo">Nama Mobil :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nama_mobil" value="<?php
echo #$detail->nama_mobil; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="nomes"></label>
<div class="col-sm-2">
<input type="submit" class="form-control" name="submit" value="simpan">
</div>
</div>
</form>
<?php $this->load->view('footer.php'); ?>
and here my pictures before click submit and after click submit. i typed print_r for see the data array. if you see data array detail before click submit, there is data in detail. but after click submit data array detail gone.
enter image description here enter image description here

Related

Why modal bootstrap on table data doesn't showing / fetching match data when popup?

Please check this image
I try to fetching data on every table data using modal bootstrap, but when i click every modal button it's just showing last table data in form of my popup modal. I want the data is per in the form on modal bootstrap. I am using CodeIgniter. Please help me, thanks. GBU
HERE IS MY CODE:
<table class="table table-bordered table-striped nowrap text-gray-900" id="dataTable" width="100%" style="font-size: 13px;" cellspacing="0">
<thead>
<tr class="table-success">
<th>ID</th>
<th>NOMOR</th>
<th>KODE</th>
<th>TINDAKAN</th>
<th>AKSI</th>
</tr>
</thead>
<tbody>
<?php
foreach ($prosedur_rehab as $rehab) {
?>
<tr>
<td><?= $rehab->ID; ?></td>
<td><?= $rehab->NOMOR; ?></td>
<td><?= $rehab->KODE; ?></td>
<td><?= $rehab->TINDAKAN; ?></td>
<td>
<button type="button" class="btn btn-sm btn-info" data-toggle="modal" data-target="#perawat<?php echo $rehab->ID;?> ">
<i class="fas fa-user-nurse"></i>
</button>
<div class="modal fade" id="perawat<?php echo $rehab->ID;?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true" >
<div class="modal-dialog modal-lg" >
<div class="modal-content">
<div class="modal-header" style="background-color:#5bc0de">
<h5 class="modal-title" id="exampleModalLabel">Kelola Rawat Jalan (Diisi Oleh Perawat)</h5>
<button type="button" class="btn-danger" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post" action="<?php echo base_url().'dokter/kunjungan/kirimlaprajal'?>">
<div class="form-group">
<!-- <label for="exampleInputEmail1">ID</label> -->
<select name="" class="form-control">
<option>-- CARI --</option>
<?php foreach ($prosedur_rehab as $rehab):?>
<option value="<?php echo $rehab->ID?>"><?php echo $rehab->ID?> || <?php echo $rehab->NORM?></option>
<?php endforeach ?>
</select>
</div>
<div class="form-group">
<label for="exampleInputEmail1">ID Prosedur</label>
<input type="text" name="ID" class="form-control" id="exampleInputEmail1" required readonly autocomplete="off" value="<?php echo $rehab->ID; ?>">
</div>
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="exampleInputEmail1">No. Pendaftaran</label>
<input type="text" name="NOMOR" class="form-control" id="exampleInputEmail1" required readonly autocomplete="off" value="<?php echo $rehab->NOMOR; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Kode</label>
<input type="text" name="KODE" class="form-control" id="exampleInputEmail1" required readonly autocomplete="off" value="<?php echo $rehab->KODE; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Tindakan</label>
<input type="text" name="TINDAKAN" class="form-control" id="exampleInputEmail1" autocomplete="off" value="<?php echo $rehab->TINDAKAN; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Tanggal</label>
<input type="datetime-local" name="TANGGAL" class="form-control" id="exampleInputEmail1" required autocomplete="off" placeholder="" value="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Instrumen Uji Fungsi</label>
<input type="text" name="PROGRAM" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Hasil</label>
<input type="text" name="HASIL" class="form-control" id="exampleInputEmail1" required autocomplete="off" placeholder="" value="">
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="exampleInputEmail1">Kesimpulan</label>
<input type="text" name="KESIMPULAN" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Rekomendasi</label>
<input type="text" name="REKOMENDASI" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Oleh</label>
<input type="text" name="OLEH" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="<?php echo $session_user->nip ;?>" readonly>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Status</label>
<input type="text" name="STATUS" class="form-control" id="exampleInputEmail1" required autocomplete="off" value="">
</div>
</div>
</div>
<button type="submit" name="simpen" class="btn btn-info float-right"><i class="fas fa-save"> </i> Simpan</button>
</form>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>NOMOR</th>
<th>KODE</th>
<th>TINDAKAN</th>
</tr>
</tfoot>
</table>
i tried your code and it works perfectly, Check your $rehave->ID value maybe it doesn't have value or have invalid value, or check your modal plugins
The problem is i was used same foreach in select option . I was forgot if i 've been using first foreach to displaying table data and i used it again in form.
Don't using same foreach in form, delete or change this:
<select name="" class="form-control">
<option>-- CARI --</option>
<?php foreach ($prosedur_rehab as $rehab):?>
<option value="<?php echo $rehab->ID?>"><?php echo $rehab->ID?> || <?php echo $rehab->NORM?></option>
<?php endforeach ?>
</select>

Codeigniter 3 select form error not showing on form submit

I was following a youtube tutorial on making a codeigniter college management system
but i am stuck at a point.. when i try to submit the form on wamp server
select form fields not showing requied error on form submit
i have checked the name fields of the form inputs matching the database table but still when the form is submitted without any fiilling any fields
the role and gender select field errors doesnt show
here is my code
controller
welcome.php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* #see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
//$this->load->helper('url');
$this->load->view('home');
}
public function adminRegister()
{
$this->load->model('queries');
$roles = $this->queries->getRoles();
// print_r($roles);
// exit();
$this->load->view('register',['roles'=>$roles]);
}
public function adminLogin()
{
echo 'Login';
}
public function adminSignup()
{
//echo 'Registered succesfully';
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('gender','Gender','required');
$this->form_validation->set_rules('role_id','Role','required');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('confpwd','Password Again','required');
$this->form_validation->set_error_delimiters('<div class="text-danger">','</div>');
if($this->form_validation->run()){
echo 'validation passed';
}else{
//echo 'validation error';
echo validation_errors();
}
}
}
and views
register.php
<?php include('inc/header.php');?>
<div class="container mt-2">
<?php echo form_open('welcome/adminSignup',['class'=>'form-hoizontal']);?>
<h3 class="text-center display-4">ADMIN REGISTER</h3>
<hr/>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label for="username" class="mt-2">User name:</label>
</div>
<div class="col-md-9">
<!-- <input type="text" class="form-control" placeholder="User name" id="username"> -->
<?php
$data = array(
'type' => 'text',
'name' => 'username',
'placeholder' => 'Enter Username',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('username','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="email" class="mt-2">Email address:</label>
</div>
<div class="col-md-9">
<!-- <input type="email" class="form-control" placeholder="Enter email" id="email"> -->
<?php
$data = array(
'type' => 'email',
'name' => 'email',
'placeholder' => 'Enter Email',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('email','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="gender" class="mt-2">Gender:</label>
</div>
<div class="col-md-9">
<!-- <input type="email" class="form-control" placeholder="Enter email" id="email"> -->
<select class="form-control" name="gender">
<option>Select</option>
<option>Male</option>
<option>Female</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('gender','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="email" class="mt-2">Role:</label>
</div>
<div class="col-md-9">
<select class="form-control" name="role_id">
<option>Select</option>
<?php if(count($roles)) { ?>
<?php foreach ($roles as $role){?>
<option><?php echo $role->rolename;?></option>
<?php }
} ?>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('role_id','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="password" class="mt-2">Password:</label>
</div>
<div class="col-md-9">
<!-- <input type="password" class="form-control" placeholder="Enter password" id="password"> -->
<?php
$data = array(
'type' => 'password',
'name' => 'password',
'placeholder' => 'Enter Password',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('password','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="password" class="mt-2">Password Again:</label>
</div>
<div class="col-md-9">
<!-- <input type="password" class="form-control" placeholder="Enter password" id="password"> -->
<?php
$data = array(
'type' => 'password',
'name' => 'confpwd',
'placeholder' => 'Enter Password Again',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('confpwd','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<!-- <button type="submit" class="btn btn-dark float-right">Register</button> -->
<div class="float-right">
<?php echo form_submit('Register', 'Register',"class='btn btn-dark'"); ?>
<?php echo anchor('welcome','GO BACK',['class'=>'btn btn-warning']);?>
</div>
</div>
</div>
<?php echo form_close(); ?>
</div>
<?php include('inc/footer.php');?>
here is screenshot
The errors are not showing because your select boxes are always submitting a value. When you select an option in the selectbox and no value attribute is specified, the value after the <option> tag is being sent to the server.
To trigger the required rule, you need to send an empty string.
To do this, you can either use an empty <option> tag for the placeholder:
<select class="form-control" name="gender">
<option></option>
<option>Male</option>
<option>Female</option>
</select>
Or set the value attribute of the placeholder to an empty string:
<select class="form-control" name="gender">
<option value="">Select</option>
<option>Male</option>
<option>Female</option>
</select>
Try below Code:
<select class="form-control" name="gender">
<option></option>
<option value="male">Male</option>
<option valie="female">Female</option>
</select>

Codeigniter Cannot submit an ip adres on a form. Throws a Forbidden error

Here is my html form.
<?php echo form_open(base_url('admin/subeler/add'), 'class="form-horizontal"'); ?>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="grup">Grup Adı</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="grup" required name="grup" value="<?php echo set_value('grup'); ?>" class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="name">Şube Adı</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="name" required name="name" value="<?php echo set_value('name'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="ip">İp Adresi</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="ip" required name="ip" value="<?php echo set_value("ip"); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="path">Database Adı</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="path" required name="path" value="<?php echo set_value('path'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="lisans">Lisans Tarihi</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="lisans" required name="lisans" value="<?php echo set_value('lisans'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="il">İl</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="il" name="il" value="<?php echo set_value('il'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="ilce">İlçe</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="ilce" name="ilce" value="<?php echo set_value('ilce'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-4 col-xs-offset-5">
<input type="submit" name="submit" value="EKLE" class="btn btn-success m-t-15 waves-effect">
</div>
</div>
<?php echo form_close();?>
When I enter an ip adres to the input field like (http://xxx.xxx.xx.xx:xx/) redirect me to the 403 Forbidden page but when I put " (like "http://xxx.xxx.xx.xx:xx") to the ip adres it work fine. I tried to disable xss-filter disable in config files but result is same. Can anyone give some advice. How to submit an ip adres correctly with Codeigniter?
Server-Side
public function add()
{
if ($this->input->post("submit")) {
$this->form_validation->set_rules('grup', 'Grup Adı', 'trim|required');
$this->form_validation->set_rules('name', 'Şube Adı', 'trim|required');
$this->form_validation->set_rules('ip', 'İp Adresi', 'trim|required');
$this->form_validation->set_rules('path', 'Database Yolu', 'trim|required');
$this->form_validation->set_rules('lisans', 'Lisans Tarihi', 'trim|required');
if ($this->form_validation->run() == true) {
$data = array(
'name' => $this->input->post('name'),
'marka' => $this->input->post('grup'),
'ip' => $this->input->post('ip'),
'il' => $this->input->post('il'),
'ilce' => $this->input->post('ilce'),
'databasePath' => $this->input->post('path'),
'lisanse_date'=>$this->input->post('lisans')
);
$data = $this->security->xss_clean($data);
$result = $this->sube_model->add_sube($data);
if ($result) {
$this->session->set_flashdata('msg', 'Şube başarılı bir şekilde eklendi!');
redirect(base_url('admin/subeler'));
}
} else {
$data['view'] = 'admin/subeler/sube_ekle';
$this->load->view('layout', $data);
}
} else {
$data['view'] = 'admin/subeler/sube_ekle';
$this->load->view('layout', $data);
}
}
Unfortunately I could not test the code exactly as provided as I don't make use of CodeIgniter 3 anymore, so I translated it into CodeIgniter 4.
Also, I could not test what $this->sube_model->add_sube does.
This, plus the form view you provided is working when setting http://xx.xx.xx.xx:xx on every form field.
You should trace when the 403 forbidden is triggered.
If you make use of XDebug i'd recommend you to trace step by step where the execution fails.
Otherwise I'd just start removing code to find out at which point of the execution the exception is occurring.
If you are making use of a shared hosting, there could be any rule in the http server that is blocking the request, if that's the case, run it locally using a WAMP/LAMP bundle.
// CodeIgniter 4 approach
public function add() {
if ($this->request->getMethod() == 'post') {
$validation = \Config\Services::validation();
$validation->setRule('grup', 'Grup Adı', 'trim|required');
$validation->setRule('name', 'Şube Adı', 'trim|required');
$validation->setRule('ip', 'İp Adresi', 'trim|required');
$validation->setRule('path', 'Database Yolu', 'trim|required');
$validation->setRule('lisans', 'Lisans Tarihi', 'trim|required');
if ($validation->withRequest($this->request)->run() == true) {
$data = array(
'name' => $this->request->getPost('name'),
'marka' => $this->request->getPost('grup'),
'ip' => $this->request->getPost('ip'),
'il' => $this->request->getPost('il'),
'ilce' => $this->request->getPost('ilce'),
'databasePath' => $this->request->getPost('path'),
'lisanse_date'=>$this->request->getPost('lisans')
);
// $data = $this->security->xss_clean($data);
$result = $this->sube_model->add_sube($data);
$result = 1;
if ($result) {
session()->setFlashdata('msg', 'Şube başarılı bir şekilde eklendi!');
return redirect(base_url('admin/subeler'));
}
} else {
$data['view'] = 'admin/subeler/sube_ekle';
return view('layout', $data);
}
} else {
$data['view'] = 'admin/subeler/sube_ekle';
return view('layout', $data);
}
}

How can I return to a form after $request->validate() errors with the input data values showing?

I'm using this code below in a Laravel controller but on errors it doesn't keep the input data when it returns to the form.
public function store(Request $request)
{
$validatedData = $request->validate([
'name' => 'required',
'intro' => 'required|max:140|min:40',
]);
If the intro is too short it sends the user back to the form but with empty fields.
The blade looks like this
<form action="{{route('member.store')}}" id="form" role="form" data-toggle="validator" method="post">
<div class="form-group">
<input type="text" value="" class="form-control" id="name" name="name" placeholder="Name" required>
</div>
<div class="form-group">
<textarea class="form-control" id="intro" rows="2" name="intro" placeholder="A short 15-30 word intro" required></textarea>
</div>
</div>
</form>
Doesn't is come with a return to the form with the data input?
You should use old('input') in the value of the input.
For your code it should be like this:
<div class="form-group">
<input type="text" value="" class="form-control" id="name" name="name" placeholder="Name" value="{{ old('name') }}" required>
</div>
<div class="form-group">
<textarea class="form-control" id="intro" rows="2" name="intro" placeholder="A short 15-30 word intro" value="{{ old('intro') }}" required></textarea>
</div>

How to make textfield automatic field when dropdown is selected in codeigniter

Hallo i'm new in codeigniter, i want to make textinput filled after selected value of dropdown, can anyone give an example for me (for models, conntroller and view) ? thx
here is my dropdown form
<div class="form-group">
<?php $id = 'id="nama" class="form-control input-md" required';
echo form_dropdown('nama',$nama_cabang,'',$id)?>
<div class="invalid-feedback">
<?php echo form_error('nama_cabang') ?>
</div>
</div>
and its my textinput
<div class="form-group">
<input class="form-control <?php echo form_error('kode_cabang') ? 'is-invalid':'' ?>"
type="text" name="kode" placeholder="Kode Cabang" />
<div class="invalid-feedback">
<?php echo form_error('kode_cabang') ?>
</div>
</div>
how can the value of textinput changed when dropdown is selected.
You could use javascript onchange listener to set the trigger, and assign the text input with the current selected value using this.value :
<div class="form-group">
<?php $id = 'id="nama" class="form-control input-md" required onchange="document.getElementById(\'kodeCabang\').value = this.value"';
echo form_dropdown('nama',$nama_cabang,'',$id)?>
<div class="invalid-feedback">
<?php echo form_error('nama_cabang') ?>
</div>
</div>
And add an id attribute (id="kodeCabang") to set the target element :
<div class="form-group">
<input class="form-control <?php echo form_error('kode_cabang') ? 'is-invalid':'' ?>" id="kodeCabang"
type="text" name="kode" placeholder="Kode Cabang" />
<div class="invalid-feedback">
<?php echo form_error('kode_cabang') ?>
</div>
</div>