[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">
<?php echo $login_error; ?>
<?php echo form_error('user_name', '<div class="errorAlert">', '</div>'); ?>
<?php echo form_error('email_address', '<div class="errorAlert">', '</div>'); ?>
<?php echo form_error('password', '<div class="errorAlert">', '</div>'); ?>
<?php echo form_error('con_password', '<div class="errorAlert">', '</div>'); ?>
</div>
<?php } ?>
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);
}