Codeigniter form_validation错误消息

时间:2018-07-12 15:05:29

标签: php codeigniter web

仅在单击表单3次后,才会显示form_validation错误消息 这是来自控制器的代码

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)){

    }
  }

这是来自查看器的代码,错误消息仅在单击表单按钮3次后才会显示

<?php if($this->session->flashdata('errors')): ?>
<?php echo $this->session->flashdata('errors'); ?>
<?php endif; ?>

1 个答案:

答案 0 :(得分:0)

会话Flash消息仅可运行一次,据我说,您的表单提交了3次提交的请求,s why It可以在Flash数据中保存3次表单错误,并在视图中显示3次。

谢谢