I am using codeigniter and have a form for add transfers. I have written validation rules in the controller but when the form submitted the errors message appear but the form forget the values which was entered by the user.
I try to use set_value and it works but sometimes I want to make if statements and I think it mus be in the controller not in the view. Is there a way to make the set value in the controller and return it in $data to the view
view
<?php $type_val= set_value('type'); ?>
<select class="form-control show-tick" id="type" name="type">
<option value="<?=set_value('type');?>" ><?=($type_val == 1) ? 'Exit' : 'Come';?></option>
<option value="1">Exit</option>
<option value="2">COME</option>
</select>
controller
public function add(){
if($this->input->post('submit')){
$rules = $this->get_rules_validation();
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == FALSE) {
$data['title'] = 'Add Transfer';
$data['view'] = 'admin/transfer/transfer_add';
$data['validation_error'] = true;
$this->load->view('layout', $data);
}
else{
$data = array(
'type' => $this->input->post('type'),
);
$data = $this->security->xss_clean($data);
$result = $this->transfer_model->add_transfer($data);
if($result){
$this->session->set_flashdata('msg', 'Transfer is Added Successfully!');
redirect(base_url('admin/transfer'));
}
else{
$this->session->set_flashdata('msg', 'Transfer Cant Be added!');
redirect(base_url('admin/transfer'));
}
}
}
else{
$data['title'] = 'Add Transfer';
$data['view'] = 'admin/transfer/transfer_add';
$this->load->view('layout', $data);
}
}