Welcome Guest, Not a member yet? Register   Sign In
Conditional Statement in View
#1

[eluser]Barwick[/eluser]
I need to create a If conditional statement in a view. But what I'm doing is not firing.
I know the the IF statement wouldn't normally be needed, but in this case I need to have one due to the styling I've created for the error message. In short, I need that errorWrap class wrapped around all the possible errors.

Here's the HTML tidbit:
Code:
<?php if($this->form_validation->run() == FALSE) { ?>
    <div class="errorWrap">          
        &lt;?php echo $login_error; ?&gt;
        
        &lt;?php echo form_error('user_name', '<div class="errorAlert">', '</div>'); ?&gt;
        &lt;?php echo form_error('email_address', '<div class="errorAlert">', '</div>'); ?&gt;
        &lt;?php echo form_error('password', '<div class="errorAlert">', '</div>'); ?&gt;
        &lt;?php echo form_error('con_password', '<div class="errorAlert">', '</div>'); ?&gt;      
    </div>
&lt;?php } ?&gt;

And the chunk of the controller that matters.

What am I doing wrong here?

Code:
public function index()
    {            
        $user = $this->session->userdata('logged_in');        
        
        if ($user == 1) // if logged in, redirect to dash
        {
            redirect('dashboard');
        }
        
        $data = array(
           'title' => 'Register',
           'login_error' => '', // required - prevents $message error created from login fail
           'menu' => '', // required - prevents $menu error as no menu is on register or login page
        );
        
        // field name, error message, validation rules (library run from autolaod)
        $this -> form_validation -> set_rules('user_name', 'Username', 'trim|required|min_length[4]|xss_clean|alpha_numeric|callback__user_check');
        $this -> form_validation -> set_rules('email_address', 'Email', 'trim|required|valid_email|callback__email_check');
        $this -> form_validation -> set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this -> form_validation -> set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');
        
        if ($this->form_validation->run())
        {
            // add & register user    
            $this -> user_model -> add_user();
            
            // login user after registration
            $email = $this -> input -> post('email');
            $password = $this -> input -> post('pass');            
            
            $result = $this -> user_model -> login($email, $password);
            if ($result)
            {
                $this -> _registration_mail();    
                // redirect set in _registration_mail method below
            }
        }
        
        // The following code will load if: invalid form submission,
        // login credentials are wrong, or standard normal page load.
        $data['scripts'] = $this -> load -> view('shared/scripts_view', '', TRUE); // adds view within view, $scripts
          
        $this -> load -> view('shared/header_view', $data);
        $this -> load -> view("registration.php", $data);
        $this -> load -> view('shared/footer_view', $data);
                                        
        
}
#2

[eluser]Mirge[/eluser]
In your view you should check the return value of validation_errors() instead.

For example:

Code:
&lt;?php if(validation_errors()) : ?&gt;
html here that shows errors.
&lt;?php endif; ?&gt;
#3

[eluser]Barwick[/eluser]
[quote author="Mirge" date="1351743459"]In your view you should check the return value of validation_errors() instead.

For example:

[code]
&lt;?php if(validation_errors()) : ?&gt;
html here that shows errors.
&lt;?php endif; ?&gt;[/quote]

Thanks for your help, Mirge! This makes a lot of sense. I was looking at it backwards. Works!
#4

[eluser]Mirge[/eluser]
Happy to help :o)




Theme © iAndrew 2016 - Forum software by © MyBB