i have a problem with form validation, this is just standart form validation.
this is weird, even i set the condition, result always pass through the condition and run "$this->model_item_management->tambah_item($item);".
my data always saved without passing form validation. I tried with dummy input $user_name and passing the data to form_validation, but didn't work either. Thank in advanced. this is my code.
public function index(){
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
//this is dummy post
$user_name = $this->input->post('user_name');
//i try to pass an input into variable and use it on form validation
$this->form_validation->set_rules('$user_name', 'username', 'required|min_length[4]');
$this->form_validation->set_rules('namaitem', 'namaitem', 'required');
$this->form_validation->set_rules('specitem', 'specitem', 'required');
$this->form_validation->set_rules('masagaransi', 'masagaransi', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('template/header');
$this->load->view('template/navigation');
$this->load->view('pages/form_tambah_item');
$this->load->view('template/footer');
} else {
$this->load->view('pages/form_sukses_simpan_item');
}
$nama_item = $this->input->post('namaitem');
$spec_item = $this->input->post('specitem');
$garansi_item= $this->input->post('masagaransi');
$item = array(
'NAMA_ITEM'=>$nama_item,
'SPEC_ITEM'=>$spec_item,
'MASA_GARANSI'=>$garansi_item
);
$this->model_item_management->tambah_item($item);
}
<div class="container">
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'form_tambah_item');
echo form_open('kontrol_tambah_item',$attributes); ?>
<div id="legend">
<legend class="">Tambah Item Form</legend>
</div>
<?php echo form_label( 'username', 'user_name' ); ?>
<?php echo form_input( 'user_name' ); ?>
<div class="control-group">
<!-- Nama item -->
<label class="control-label" for="namaitem">Nama Item</label>
<div class="controls">
<input type="text" id="namaitem" name="namaitem" placeholder="" class="input-xlarge">
<p class="help-block">Masukkan nama dari items</p>
</div>
</div>
<div class="control-group">
<!-- spec item-->
<label class="control-label" >Spesifikansi Item</label>
<div class="controls">
<textarea class="input-xlarge" id="specitem" name="specitem" cols="40" rows="5"></textarea>
<p class="help-block">Isi Spesifikasi Item</p>
</div>
</div>
<div class="control-group">
<!-- Masa garansi -->
<label class="control-label" for="masagaransi">Masa garansi</label>
<div class="controls">
<input type="text" id="masagaransi" name="masagaransi" placeholder="" class="input-xlarge">
<p class="help-block">Isi Masa Garansi Item</p>
</div>
</div>
<div class="control-group">
<!-- Button -->
<div class="controls">
<button type="submit" class="btn btn-success">Tambah</button>
</div>
</div>
</div>
if ($this->form_validation->run() == FALSE)toif ($this->form_validation->run($this) == FALSE)