如何在不使用javascript的情况下在codeigniter中形成弹出模型验证

时间:2017-03-20 06:09:14

标签: codeigniter bootstrapping

how to form popup model validation in codeigniter without using javascript and jquery 如何在不使用javascript和jquery的情况下在codeigniter中形成弹出模型验证

 public function login() {
                $email = $this->input->post('email');
                $password = $this->input->post('password');

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

                $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
                $this->form_validation->set_rules('password', 'password', 'trim|required|min_length[4]|max_length[40]');

                if ($this->form_validation->run() && $this->Login_model->loginn($email, $password)) { 
                    $this->welcome();
                } else {
                    $this->form_validation->set_message('check_database', 'Invalid username or password');
                    $this->index();
                }
            }

查看页面,如何在不使用javascript和jquery的情况下在codeigniter中形成弹出模型验证

<form   id="register-form" onsubmit ="return validateForm()" action="<?php echo base_url(); ?>Index.php/Login_cntrl/login" method="POST" >

                    <div class="field-wrap">
                        <label class="view-label">Email Address</label>
                        <input type="email" placeholder="Email Address" name="email" id="email" class="input-control" value=""/>

                    </div>

                    <div class="field-wrap">
                        <input type="password" placeholder="Password" name="password" id="password" value="" />

                        <a href="javascript:void(0)" class="btn btn-link btn-nobg" id="btn-show-forgot" >Forgot ?</a>  

                    </div>


                    <div class="field-wrap">
                        <button type="submit" class="btn btn-submit" name="ulogin" id="ulogin" value="ulogin" >Login</button>
                    </div>
                    <div class="field-wrap">
                        <a href="javascript:void(0)" class="btn btn-link btn-nobg" id="btn-show-signup">NEW User? Sign up</a>
                    </div>

                </form>

模型代码,如何在不使用javascript和jquery的情况下在codeigniter中形成弹出模型验证

public function loginn($email, $password) {

       // $this->db->where('email', $email);

        $where="(email='$email' or mobile_no='$email') and password='$password'";

        $this->db->where($where);

        $query = $this->db->get('customer_registration');

        $count = $query->num_rows(); //counting result from query

        if ($count === 0) {
           // $this->db->where('email', $email);
          $where="(email='$email' or mobile_no='$email') and password='$password'";

        $this->db->where($where);
      //  $this->db->where('password', $password);
        $query = $this->db->get('supplier_registration');

        }

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                //add all data to session
                $newdata = array(
                    'id' => $row->id,
                    'first_name' => $row->first_name,
                    'last_name' => $row->last_name,
                    'email' => $row->email,
                    'password' => $row->password,
                    'mobile_number' => $row->mobile_number,
                    'logged_in' => TRUE,
                );
            }
            $this->session->set_userdata($newdata);
            return true;
        }
        return false;
    }

1 个答案:

答案 0 :(得分:4)

以下显示的代码工作正常

公共功能登录($ email,$ password){

        // $this->db->where('email', $email);

        $where = "(email='$email' or mobile_no='$email') and password='$password'";

        $this->db->where($where);

        $query = $this->db->get('customer_registration');

        $count = $query->num_rows(); //counting result from query
        $tablename = "customer";
        if ($count === 0) {
            // $this->db->where('email', $email);
            $where = "(email='$email' or mobile_no='$email') and password='$password'";

            $this->db->where($where);
            //  $this->db->where('password', $password);
            $query = $this->db->get('supplier_registration');
            $tablename = "supplier";
        }

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                //add all data to session
                $newdata = array(
                    'id' => $row->id,
                    'first_name' => $row->first_name,
                    'last_name' => $row->last_name,
                    'email' => $row->email,
                    'password' => $row->password,
                    'mobile_number' => $row->mobile_number,
                    'log_in' => TRUE,
                );
            }
            $this->session->set_userdata($newdata);
            return $tablename;
        }
        return $tablenam = " '";
    }