I am validating a form in codeigniter. If the user did not fill in the form correctly, then the page should not redirect to any other page, but display errors on each input field. Here is my code of form:
<?php echo $this->session->flashdata('errors');?>
<form action="<?php echo base_url() ?>detail/travel" method="post">
<input type="text" name="departure">
<input type="text" name="destination">
<input type="text" name="name">
<input type="text" name="cell">
</form>
and here is my method code:
function search_travel(){
if($_POST){
$config = array(
array(
'field'=>'departure',
'label'=>'departure',
'rules'=>'trim|required|alpha'
),
array(
'field'=>'destination',
'label'=>'destination',
'rules'=>'trim|required|alpha'
),
array(
'field'=>'name',
'label'=>'name',
'rules'=>'trim|required|alpha'
),
array(
'field'=>'cell',
'label'=>'cell no',
'rules'=>'trim|required'
)
);
$this->load->library('form_validation');
$this->load->helper(array('form', 'url'));
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){
$this->session->set_flashdata('errors', validation_errors());
redirect(base_url());
}
}
}
The problem is that by using set_flashdata I can't use form_error function and set_value function. Is there any other solution to this problem???