Welcome Guest, Not a member yet? Register   Sign In
Form validation by my own method
#3

Hey Valery,

If your using form validation, you can use your own function as a callback function to do the necessary checks. You would have to change a couple of things, because a validation function can only pass through the form input which is checked.

You could set it up like this (taken from the user guide with some changes):

PHP Code:
        public function index()

        {
                $this->load->helper(array('form''url'));

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

                $this->form_validation->set_rules('username''Username''callback_username_check');
                $this->form_validation->set_rules('password''Password''required');
                $this->form_validation->set_rules('passconf''Password Confirmation''required');
                $this->form_validation->set_rules('email''Email''required|is_unique[users.email]');

                if ($this->form_validation->run() == FALSE)
                {
                        $this->load->view('myform');
                }
                else
                {
                        $this->load->view('formsuccess');
                }
        }


        public function username_check($username)

        {
                $password $this->input->post("password");
               
                $this
->load->model("users");
               
                
// use a model function to check the credentials
                return $this->users->check_user_pass($username$password);
                
                
// notice: get_access has to return true for success or false when user and/or password are wrong, because you have to tell form validation if your validation checks out or not.
               
        


And here you have a username/password validation workaround for 2 variables. Wink

Happy coding!
Reply


Messages In This Thread
Form validation by my own method - by Valery - 04-25-2015, 09:07 AM
RE: Form validation by my own method - by Valery - 04-28-2015, 04:20 AM
RE: Form validation by my own method - by RogerMore - 04-27-2015, 12:23 AM
RE: Form validation by my own method - by Valery - 04-28-2015, 04:12 AM
RE: Form validation by my own method - by CroNiX - 04-28-2015, 11:33 AM
RE: Form validation by my own method - by Valery - 04-29-2015, 07:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB