Welcome Guest, Not a member yet? Register   Sign In
Help with User Registration Function?
#8

[eluser]Corey Freeman[/eluser]
@Buso
Not to me it wasn't....

I ended up with something that works finally! Smile

Code:
<?php

class Register extends Controller {

    function register()
    {
        parent::Controller();
        $this->load->helper('form');
        $this->load->helper('url');    
        $this->load->library('form_validation');
    }
    
    function index()
    {
        $this->load->view('header');
        redirect('register/register_form');
        $this->load->view('footer');
    }
    function register_form() {
        $this->form_validation->set_rules('username', 'Username', 'callback_check_username');
        $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'callback_check_email');
        if ($this->form_validation->run() == FALSE)
        {
        $this->load->view('header');
        $this->load->view('register_form');
        $this->load->view('footer');        }
        else
        {
            //Register the Player
            $this->register_member();
            //Show the Next Page
            redirect('register/success');
        }
    }
    //
    function check_username($str) {
        //Does the Username Exist?
        $query = $this->db->get('players');
        foreach ($query->result() as $row):
        $username_exist = $row->username;
        if ($str == $username_exist)
        {
            return FALSE;
            $this->form_validation->set_message('username', 'Email Invalid');

        }
        else
        {
            return TRUE;
        }
        endforeach;
    }
    //Does the Email Exist?
    function check_email($str) {
        //Does the Username Exist?
        $query = $this->db->get('players');
        foreach ($query->result() as $row):
        $email_exist = $row->email;
        if ($str == $email_exist)
        {
            return FALSE;
            $this->form_validation->set_message('email', 'Email Invalid');

        }
        else
        {
            return TRUE;
        }
        endforeach;
    }
    //Register the New User Please :)
    function register_member() {
            $username = $_POST['username'];
            $password = $_POST['password'];
            $email = $_POST['email'];
            $this->db->insert('players', $_POST);
    }
    //
    function success() {
        $this->load->view('header');
        $this->load->view('register_success');
        $this->load->view('footer');
    }
}

?>

Not the most secure or pretty code ever but it works for my first try...thanks for the help everyone. Smile I'll check out that thread.


Messages In This Thread
Help with User Registration Function? - by El Forum - 07-02-2010, 06:31 AM
Help with User Registration Function? - by El Forum - 07-02-2010, 07:30 AM
Help with User Registration Function? - by El Forum - 07-02-2010, 08:00 AM
Help with User Registration Function? - by El Forum - 07-02-2010, 11:47 AM
Help with User Registration Function? - by El Forum - 07-02-2010, 12:22 PM
Help with User Registration Function? - by El Forum - 07-02-2010, 12:23 PM
Help with User Registration Function? - by El Forum - 07-02-2010, 02:46 PM
Help with User Registration Function? - by El Forum - 07-02-2010, 02:51 PM
Help with User Registration Function? - by El Forum - 07-02-2010, 04:20 PM
Help with User Registration Function? - by El Forum - 07-02-2010, 06:36 PM
Help with User Registration Function? - by El Forum - 07-03-2010, 03:29 AM
Help with User Registration Function? - by El Forum - 07-03-2010, 06:29 AM
Help with User Registration Function? - by El Forum - 07-04-2010, 06:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB