简体   繁体   English

Codeigniter form_validation错误消息

[英]Codeigniter form_validation error message

the form_validation error message is showing up only after 3 times of clicking on the form this is the code from the controller 仅在单击表单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)){

    }
  }

and this is the code from the viewer , the error messages is showing up but only after 3 times clicking on form button 这是查看器的代码,错误消息仅在单击表单按钮3次后显示

<?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. Session Flash Message仅一次运行,据我说您的表单提交了3次提交请求,这s why It在Flash数据中保存3次表单错误并在视图中显示3次的原因。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM