Do form validation with jquery ajax in codeigniter

后端 未结 6 1018
猫巷女王i
猫巷女王i 2020-12-03 22:34

How can i do form validation in codeigniter if i don\'t want to refresh the page? Basically i do this:

    $config = array(
            array(
                       


        
6条回答
  •  清歌不尽
    2020-12-03 23:22

    If you gave your JS- jquery Ajax code it would more efficient to understand your problem.. Don't worry! Try my following instruction...

    1) Get get form value and pass to form as

    
    

    Controller :

    1. Load library form_validation in construct as ...

      $this->load->library('form_validation');

      $this->load->helper('form');

    2. Now write your controller as ...

      function MethodName {
      $this->form_validation->set_error_delimiters('', '');
      $this->form_validation->set_rules('fname','First Name', 'required');
      $this->form_validation->set_rules('lname','Last Name', 'required');
      $this->form_validation->set_rules('email','Email Address','required|valid_email|is_unique[sec_users.email]');
      if ($this->form_validation->run() == FALSE) {
          echo validation_errors();
      } 
      else {
        // To who are you wanting with input value such to insert as 
        $data['frist_name']=$this->input->post('fname');
        $data['last_name']=$this->input->post('lname');
        $data['user_name']=$this->input->post('email');
        // Then pass $data  to Modal to insert bla bla!!
      }
      

      }

    Hope will work as it is working in my application.

    Please accept if it is the best answer.

    Thank you!

提交回复
热议问题