Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] view not showing if called just before a die()
#1

[eluser]zamrg[/eluser]
I have a registration form which if successful, shows a view and calls a die() to prevent the script from continuing to show the form again (with any errors).

The problem occurs with the code segment

Code:
$data['content'] = 'user/register_success';
                $this->load->view('template', $data);
                die();

I get no output if I keep the die(), however if I remove it, CI outputs both views (which is correct), but not what I'm looking for.

.. and here is a full copy of the register() function in my controller

Code:
function register()
    {
        // redirect user to portal if already logged in
        if (is_logged_in())
        {
            redirect('/user/portal');
        }
        
        $this->load->library('email');
        $this->load->library('form_validation');
        
        $this->load->helper('string');
        
        $data['errors'] = array();
        
        // check if form was submitted
        if (count($_POST) > 0)
        {
            $this->form_validation->set_error_delimiters('<div class="form-error">', '</div>');
            $this->form_validation->set_rules('username', 'lang:register.username', 'required|alpha_dash|min_length[' . $this->config->item('username_min_length') . ']|max_length[' . $this->config->item('username_max_length') . ']|callback__username_duplicate_check');
            $this->form_validation->set_rules('email', 'lang:register.email', 'required|valid_email|max_length[120]|callback__email_duplicate_check');
            $this->form_validation->set_rules('password', 'lang:register.password', 'required|min_length[' . $this->config->item('password_min_length') . ']|max_length[' . $this->config->item('password_max_length') . ']');
            $this->form_validation->set_rules('confirm_password', 'lang:register.confirm_password', 'required|min_length[' . $this->config->item('password_min_length') . ']|max_length[' . $this->config->item('password_max_length') . ']|matches[password]');
            
            // check if form data passes validation
            if ($this->form_validation->run())
            {
                // generate a random activation code
                $activation_code = random_string('alnum', 20);
                
                // prepare data for database entry
                $insert_data = array(
                    'username' => $this->input->post('username'),
                    'email' => $this->input->post('email'),
                    'password' => $this->_prep_password($this->input->post('password')),
                    'group_id' => $this->config->item('default_group_id'),
                    'activation_code' => $activation_code,
                    'join_date' => time()
                );
                
                // create user in database
                $user_id = $this->user->create($insert_data);
                
                // send activation e-mail to user
                $email_data = array(
                    'username' => $this->input->post('username'),
                    'site_name' => $this->config->item('site_name'),
                    'activation_link' => site_url('user/activate_account/' . $user_id . '/' . $activation_code),
                    'support_email' => $this->config->item('site_support_email')
                );
                
                $this->email->from($this->config->item('site_noreply_email'), $this->config->item('site_name'));
                $this->email->to($this->input->post('email'));
                $this->email->subject(lang('email.activation.subject'));
                $this->email->message_from_view('activation', $email_data);
                
                if (!$this->email->send())
                {
                    // failed to send activation e-mail
                    // TODO: log event
                }
                
                // show success page
                $data['email'] = $this->input->post('email');
                $data['support_email'] = $this->config->item('site_support_email');
                $data['title'] = lang('register.title');
                $data['content'] = 'user/register_success';
                $this->load->view('template', $data);
                die();
            }
        }
        
        $data['title'] = lang('register.title');
        $data['content'] = 'user/register';
        $this->load->view('template', $data);
    }


Messages In This Thread
[SOLVED] view not showing if called just before a die() - by El Forum - 01-10-2010, 03:13 PM
[SOLVED] view not showing if called just before a die() - by El Forum - 01-10-2010, 03:33 PM
[SOLVED] view not showing if called just before a die() - by El Forum - 01-10-2010, 03:36 PM
[SOLVED] view not showing if called just before a die() - by El Forum - 01-10-2010, 03:51 PM
[SOLVED] view not showing if called just before a die() - by El Forum - 01-10-2010, 04:00 PM
[SOLVED] view not showing if called just before a die() - by El Forum - 01-10-2010, 04:36 PM
[SOLVED] view not showing if called just before a die() - by El Forum - 01-10-2010, 04:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB