form validation help PLEASE

#1
[eluser]dadamssg[/eluser]
im trying to get a simple login to work with a callback function i created to make sure the password the person entered matches a username they entered in a form. right now if i leave the fields blank and push submit i get "Empty fields", which is right. But if i enter something in both...i get "It WORKED."...which it doesn't work. The username and password im entering do not match so it should return FALSE. any help please?
Code:
<?php

class Login extends Controller {

    function Login()
    {
        parent::Controller();
        $this->load->database();
        $this->load->library('session');
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
    }

    function index()
    {
        
        
        $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_username_check');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|');
        
        
                if ($this->form_validation->run() == FALSE)
                {
                    $this->session->set_flashdata('message', 'Empty Fields.');
                    redirect('mains');
                }
                else
                {
                    
                    $this->session->set_flashdata('message', 'It WORKED.');
                    redirect('mains');
                }
    
        
        function username_check()
        {
            $user = $this->input->post('username');
            $pass = $this->input->post('password');
            $query = $this->db->query("SELECT loginName,active FROM Member WHERE loginName='$user'
                                AND password=md5('$pass')");
                if($query->num_rows() == 1)
                {
                return TRUE;
                }
                else
                {
                return FALSE;
                }
        
        }
    
    
}
}

?>

#2
[eluser]JHackamack[/eluser]
A few things,

Have you tried renaming username_check to "verifyuser" something without the underscore. Also when the user put in their initial password did you md5 it?

#3
[eluser]dadamssg[/eluser]
hey thanks for the reply but yes i just tried something with no underscore with no avail and yes the passwords are md5'ed. I don't know what the heck im doing wrong...

#4
[eluser]JHackamack[/eluser]
In looking at the example I can see one difference that might affect it:

Example Code:
$this->load->library('validation');

$rules['username'] = "required";
$rules['password'] = "required";
$rules['passconf'] = "required";
$rules['email'] = "required";

$this->validation->set_rules($rules);


Your Code
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_username_check');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|');


The bottom rule might be overwriting the top rule when it processes it, so you lose the username_check. Try setting as an array first

#5
[eluser]dadamssg[/eluser]
im pretty sure that part is right...this is also in the user guide which is what i was referencing when i wrote it

$this->form_validation->set_rules('username',username','trim|required|min_length[5]|max_length[12]|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|matches[passconf]|md5');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

#6
[eluser]dadamssg[/eluser]
for whatever reason it won't let me use my callback function i created...FRUSTRATING

#7
[eluser]JHackamack[/eluser]
Are you referencing the current documentation?
http://www.codeignitor.com/user_guide/li...ation.html

Because also the current documentation also calls your "form_validation" just "validation"

#8
[eluser]dadamssg[/eluser]
http://ellislab.com/codeigniter/user-gui...#callbacks

thats what im referencing...its in their user guide..it SHOULD be current

#9
[eluser]JHackamack[/eluser]
This might be more of a my error not checking out everything. I guess I messed up on that one, thats a my bad. Can you be sure that the username_check function isn't firing off, or that it might be querying incorrectly.

As in putting a echo $this->db->last_query(); die(); to see if its getting to the username_check validation?

#10
[eluser]dadamssg[/eluser]
hmm good idea...yeah its not pulling up that query. wtf


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.