Welcome Guest, Not a member yet? Register   Sign In
form validation help PLEASE
#11

[eluser]JHackamack[/eluser]
Do you have errors being displayed so you'd know if there was a problem? Have you double checked your database config file.
#12

[eluser]dadamssg[/eluser]
yeah i definitely have errors being displayed but there are none on this and yeah my database config file is working because i use it on another controller and it works. i think my validation library is jacked
#13

[eluser]JHackamack[/eluser]
It seems like something is up. Did you copy and past alot of this from the example code online? If so i've found that alot of times there are hidden characters which mess up php and it might not tell you about. Its usually just the spaces that has the problem. Anything else and i'd just start figuring what works by slowly taking away things and figuring out where its dying.
#14

[eluser]dadamssg[/eluser]
no..i wrote it all my self but looking closely at the example. Yeah i just cant get any kind of call back function working. ive changed it to not even use the db but still nothing.
#15

[eluser]dadamssg[/eluser]
I THINK I FINALLY GOT IT WORKING Smile....sort of. I noticed that the callback function has to be OUTSIDE of the index function and the md5 in the rules isn't working. so i'm md5ing it in the query as well and it works...heres the working code. that still bugs me why the md5 wont work :/
Code:
<?php

class Login extends Controller {

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

    function index()
    {
        
        
        $this->load->library('validation');    
        $rules['username']    = "required|callback_username_check";
        $rules['password']    = "md5|required";
        
        
        $this->validation->set_rules($rules);
        
        
                if ($this->validation->run() == FALSE)
                {
                    $this->session->set_flashdata('message', 'Doesnt Match.');
                    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() > 0)
                {
                return TRUE;
                }
                else
                {
                return FALSE;
                }
        
        }
}

?>
#16

[eluser]flaky[/eluser]
from what I'm seeing you've put the callback function inside the index(), which is wrong, at least php should be giving you a warning about that, you can't have a function inside a function

here the fix
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;
        }
        
    }
}

?>
#17

[eluser]JHackamack[/eluser]
Yeah, that was the one thing I was debating on was copying it into my text editor and line up the brackets. Luckily you found out that solution. The MD5 thing can work I would assume, but you can try

$pass = md5($this->input->post('password');
and make php do the lifting
#18

[eluser]flaky[/eluser]
also when using md5 keep in mind to use salts, at least you get some protection against rainbow tables
#19

[eluser]JHackamack[/eluser]
And to link to another article here:
http://ellislab.com/forums/viewthread/140522/
#20

[eluser]dadamssg[/eluser]
salts?




Theme © iAndrew 2016 - Forum software by © MyBB