• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do you handle form submissions

#8
[eluser]jvittetoe[/eluser]
Ok, i have a new idea on how to handle my logins / new registrations. upon coming to the site the default controller is welcome.php from here there is one form which submits a post array, containing an email address and a password, to the welcome/checkUser method is my welcome controller. this method checks to see if the submitted email address is already taken. if it is, redirect users to the welcome/doLogin method, if its not taken, redirect users to the welcome/doRegister method. and while inside welcome/doRegister, once the registration has returned from the model, i want to redirect users to the welcome/doLogin method to be automatically logged in. im having the hardest time getting things to work.

Code:
function checkUser(){
        $this->load->library('validation');
        $this->load->model('User_model');
        $validUser = $this->User_model->checkEmailExists($this->validation->emailaddress, $this->session->userdata('session_id'));
        
        if($validUser){
            $this->doLogin();
        } else {
            $this->doRegister();
        }
    }
Code:
function doLogin(){
        $this->load->library('validation');
        $this->load->helper( array('url', 'form', 'date') );
        $this->load->model('User_model');
        
        $user_id = $this->User_model->login($this->validation->emailaddress, $this->validation->password, $this->session->userdata('session_id'));

        if($user_id != 0){
            
            // succsessful login
            $this->session->set_userdata(array('user_id' => $user_id));
            $data['user'] = $this->User_model->getDetails($user_id);
            $data['title'] = "My Finance - v1.0 ~ Dashboard";
            
            redirect('/dashboard/overview', 'refresh');
            //$template['mainContent'] = $this->load->view('dspDashboard', $data, true);
            //$this->load->view('layDash', $template);

        } else {
            
            // login failed
            $data['title'] = "My Finance - v1.0 ~ Home";
            //redirect('/welcome', 'refresh');
            $template['mainContent'] = $this->load->view('dspHome', $data, true);
            $this->load->view('layMain', $template);
        }
    }
Code:
function doRegister(){
        $this->load->library('validation');
        $this->load->helper( array('url', 'form', 'date') );
        $this->load->model('User_model');
        
        $user_id = $this->User_model->register($this->validation->emailaddress, $this->validation->password, $this->session->userdata('session_id'));
        
        if($user_id > 0){
            
            // successful registration
            //$this->doLogin();
            $user_id = $this->User_model->login($this->validation->emailaddress, $this->validation->password, $this->session->userdata('session_id'));

            if($user_id != 0){
            
                // succsessful login
                $this->session->set_userdata(array('user_id' => $user_id));
                $data['user'] = $this->User_model->getDetails($user_id);
                $data['title'] = "My Finance - v1.0 ~ Dashboard";
        
                //redirect('/dashboard', 'refresh');
                //$template['mainContent'] = $this->load->view('dspDashboard', $data, true);
                //$this->load->view('layDash', $template);

            } else {
            
                // login failed
                $data['title'] = "My Finance - v1.0 ~ Home";
                //redirect('/welcome', 'refresh');
                $template['mainContent'] = $this->load->view('dspHome', $data, true);
                $this->load->view('layMain', $template);
            }
            
        } else {
            
            // failed registration            
            $data['title'] = "My Finance - v1.0 ~ Home";
            redirect('/welcome', 'refresh');
                
        }
    }

now my question is how can i pass my $data variable when using a redirect. because all of this is taking place in my welcome controller. so once someone logs in, they are taken to the dashboard controller. if i uncomment the redirect lines and using the load->view my url stays www.com/welcome/home instead of www.com/dashboard.


Messages In This Thread
how do you handle form submissions - by El Forum - 08-31-2007, 04:05 PM
how do you handle form submissions - by El Forum - 09-01-2007, 12:11 AM
how do you handle form submissions - by El Forum - 09-02-2007, 10:17 PM
how do you handle form submissions - by El Forum - 09-03-2007, 02:07 PM
how do you handle form submissions - by El Forum - 09-03-2007, 04:47 PM
how do you handle form submissions - by El Forum - 09-04-2007, 06:27 AM
how do you handle form submissions - by El Forum - 09-04-2007, 07:22 AM
how do you handle form submissions - by El Forum - 09-04-2007, 04:23 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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