Welcome Guest, Not a member yet? Register   Sign In
Form Validation Question
#1

I have a login form like below and on my rules I have a validate_password that I have set in a MY_Form_validation.php

When there is a error for the validate_password it shows up in the password form_error.

Question is there away that I can have the validate password in my password rules but have that error message show some where else I only want the required messages to show in with password rules.

MY_Form_validation


PHP Code:
<?php

class MY_Form_validation extends CI_Form_validation {

    public function __construct() {
        parent::__construct();
        $this->CI =& get_instance();
    }

    public function validate_password() {
        $password $this->CI->input->post('password'true);
        $stored_hash $this->stored_hash();

        if (password_verify($password$stored_hash)) {
            return true;
        } else {
            $this->set_message('validate_password'"Opps somethings gone worng!");
            return false;
        }
    }

    public function stored_hash() {
        $this->CI->db->select('password');
        $this->CI->db->from($this->CI->db->dbprefix 'user');
        $this->CI->db->where('username'$this->CI->input->post('username'true));
        $query $this->CI->db->get();

        if ($query->num_rows() > 0) {
            return $query->row()->password;
        }
    }




Controller



PHP Code:
<?php

class Login extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library(array('form_validation''user_agent'));
        $this->load->model('user/user_model');
    }

    public function index() {
        $this->data['google_login_url'] = $this->googleplus->loginURL();

        $config = array(
            array(
                'field' => 'username',
                'label' => 'Username',
                'rules' => 'required'
                ),
            array(
                'field' => 'password',
                'label' => 'Password',
                'rules' => 'required|validate_password',
                'errors' => array(
                'required' => 'You must provide a %s.',
                ),
            ),
              
        
);

        $this->form_validation->set_rules($config);

        if ($this->form_validation->run() == TRUE) {

        }

        $this->data['header'] = $this->header();
        $this->data['footer'] = $this->footer();
        $this->data['menu'] = $this->menu();
        
        $this
->load->view('default/template/users/login_view'$this->data);
    
    
}

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB