0
votes

This is my view page code

i check codeigniter form validation in codeigniter it's copy and paste my controller but same error

<form action="<?php echo base_url(); ?>admin/user_setup/store" method="post" class="ml-4 mr-4 mt-2" enctype="multipart/form-data">
                <div class="row">
                      <div class="col-lg-3 col-md-6 col-sm-12">
                          <div class="form-group form__group">
                              <input type="text" name="firstname" id="firstname" placeholder="নাম" class="form-control form__field" required>
                              <label for="firstname" class="form__label">নাম  </label>
                          </div>
                      </div>
                      <div class="col-lg-3 col-md-6 col-sm-12">
                          <div class="form-group form__group">
                              <input type="text" name="username" id="username" placeholder="ইউজার নাম" class="form-control form__field" required>
                              <label for="username" class="form__label">ইউজার নাম  </label>
                          </div>
                      </div>
                      <div class="col-lg-3 col-md-6 col-sm-12">
                          <div class="form-group form__group">
                              <input type="text" name="email" id="email" placeholder="ই-মেইল" class="form-control form__field" required>
                              <label for="email" class="form__label">ই-মেইল  </label>
                          </div>
                      </div>
                      <div class="col-lg-3 col-md-6 col-sm-12">
                          <div class="form-group form__group">
                              <select name="activated" id="activated" class="form-control form__field" >
                                <option value="1">Active</option>
                                <option value="0">Inactive</option>
                              </select>
                              <label for="activated" class="form__label">অ্যাক্টিভেটেড</label>
                          </div>
                      </div>
                      <div class="col-lg-3 col-md-6 col-sm-12">
                          <div class="form-group form__group">
                              <input type="password" name="password" id="password" placeholder="পাসওয়ার্ড" class="form-control form__field" required>
                              <label for="password" class="form__label">পাসওয়ার্ড</label>
                          </div>
                      </div>
                      <div class="col-lg-3 col-md-6 col-sm-12">
                          <div class="form-group form__group">
                              <input type="password" name="confirm_password" id="confirm_password" placeholder="কন্ফার্ম পাসওয়ার্ড" class="form-control form__field" required>
                              <label for="confirm_password" class="form__label">কন্ফার্ম পাসওয়ার্ড</label>
                          </div>
                      </div>
                      <div class="col-lg-2 col-md-6 col-sm-12">
                          <div class="form-group form__group">
                              <label for="logo" class="form__label">ছবি </label>
                              <input type="file" name="logo" id="logo" placeholder="ছবি" class="form-control form__field" rows="2" cols="2" style="height: 38px;"></input>
                          </div>
                      </div>
                      <div class="col-lg-2 col-md-6 col-sm-12">
                          <div class="form-group form__group">
                              <select name="type" id="type" class="form-control form__field" >
                                    <option value="2">এডিটর</option>
                                    <option value="3">লাইসেন্স অফিসার</option>
                              </select>
                              <label for="type" class="form__label">ইউজার টাইপ</label>
                          </div>
                      </div>
                      <div class="col-lg-2 col-md-6 col-sm-12">
                          <div class="form-group">
                              <input type="submit" value="তৈরি করুন"  class="form-control btn btn-sm btn-primary mt-fl">
                          </div>
                      </div>
                  </div>
            </form>

this is my controller code

  $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[100]|alpha_dash');
            $this->form_validation->set_rules('firstname', 'First Name', 'trim|required|xss_clean|min_length[6]|max_length[100]|alpha_dash');
            $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email');
            $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|minlength[6]|max_length[50]|alpha_dash');
            $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean|matches[password]');
    
            $data['errors'] = array();
            echo $this->form_validation->set_value('username');
    
            echo  $this->input->post('username');
    
            if ($this->form_validation->run()) {
    
                $data['username']    = $this->form_validation->set_value('username');
                $data['firstname']   = $this->form_validation->set_value('firstname');
                $data['email']       = $this->form_validation->set_value('email');
                $data['password']    = $this->form_validation->set_value('password');
                $data['created']     = date('Y-m-d H:i:s');
                $data['activated']   = $this->input->post('activated');
                $data['type']        = $this->input->post('type');
                
                $insert_id = $this->web_model->insert('users', $data);
                var_dump("asduasiduiasdijasidij");
            } else {    
                $errors = $this->tank_auth->get_error_message();
                
                foreach ($errors as $k => $v)   $data['errors'][$k] = $this->lang->line($v);
                // $this->render_page('admin/setup/user_setup/create', $data);
                echo $this->form_validation->run();
                var_dump($data['errors']);
            }

form validation don't return anything and $this->form_validation->set_value('any'); is always be empty

I load form_validation in controller __construct and also check load function inner but error is absolute

 $this->load->helper(array('form', 'url'));
 $this->load->library('form_validation');
1
You should use $this->input->post('fieldname') to assign the field value to a variable. The set_value method is used to populate a form field in case validation fails. The fact that the run() method does not return anything (visible) is very accurate, as it will only return a boolean (true/false) depending on validation passing or failingJavier Larroulet

1 Answers

0
votes

Check your PHPMyAdmin, I got the same problem last month, find xampp with build in PHP 5.6, link here https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/5.6.40/ , delete or rename your old Windows(c:)/xammp/ and replace with PHP 5.6