the form_validation error message is showing up only after 3 times of clicking on the form this is the code from the controller
public function add_product() {
$this->form_validation->set_rules('product_title', 'Product title','trim|required|min_length[2]');
$this->form_validation->set_rules('product_description', 'Product description','trim|required');
$this->form_validation->set_rules('product_price', 'Product price','trim|required|greater_than[0]');
$this->form_validation->set_rules('product_quantity', 'Product quantity','trim|required');
$data['main_view']= 'admin/products/add_product';
$this->load->view('admin/index',$data);
if($this->form_validation->run() == false) {
$data_error = array('errors' => validation_errors());
$this->session->set_flashdata($data_error);
}else {
$title = $this->input->post('product_title');
$description = $this->input->post('product_description');
$price = $this->input->post('product_price');
$quantity = $this->input->post('product_quantity');
$data = array('title'=>$title, 'description'=>$description, 'price'=>$price, 'quantity'=>$quantity);
if($this->Products_model->create_product($data)){
}
}
and this is the code from the viewer , the error messages is showing up but only after 3 times clicking on form button
<?php if($this->session->flashdata('errors')): ?>
<?php echo $this->session->flashdata('errors'); ?>
<?php endif; ?>
Session Flash Message work only single time, according to me your form submit a request submitting 3 times, that s why It
s saving form error 3 times in flash data and showing 3 times on view.
Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.