Welcome Guest, Not a member yet? Register   Sign In
Form errors not showing.
#1

[eluser]austintbiggs[/eluser]
No matter what I do I can't seem to get the Ion Auth errors to display although I believe the issue lies in standard php and codeigniter. Anyone have ideas?

in the controller
Code:
function login()
    {
        $this->data['title'] = "Login";

        //validate form input
        $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required');

        if ($this->form_validation->run() == true)
        { //check to see if the user is logging in
            //check for "remember me"
            $remember = (bool) $this->input->post('remember');

            if ($this->ion_auth->login($this->input->post('email'), $this->input->post('password'), $remember))
            { //if the login is successful
                //redirect them back to the home page
                $this->session->set_flashdata('message', $this->ion_auth->messages());
                redirect($this->config->item('base_url'), 'refresh');
            }
            else
            { //if the login was un-successful
                //redirect them back to the login page
                $this->session->set_flashdata('message', $this->ion_auth->errors());
                redirect('login', 'refresh'); //use redirects instead of loading views for compatibility with MY_Controller libraries
            }
        }
        else
        {  //the user is not logging in so display the login page
            //set the flash data error message if there is one
            $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

            $this->data['email'] = array('name' => 'email',
                'id' => 'email',
                'type' => 'text',
                'value' => $this->form_validation->set_value('email'),
            );
            $this->data['password'] = array('name' => 'password',
                'id' => 'password',
                'type' => 'password',
            );

            $this->load->view('body/login', $this->data);
        }
    }

within the view
Code:
<div id="infoMessage">&lt;?php echo $message;?&gt;</div>
    &lt;?php $email = array('class' => 'indent round_all'); $password = $email;
    echo form_open('body/login'); ?&gt;        
    
            <label class="fields"><strong>Username</strong>
      &lt;?php echo form_input($email);?&gt;</label>

            <label class="fields"><strong>Password</strong>
      &lt;?php echo form_password($password);?&gt;</label>
      
            <button class="button_colour round_all" type="submit"><img width="24" height="24" alt="Locked 2" src="../beauty/images/body/icons/small/white/Locked 2.png"><span>Login</span></button>
            
      <div id="bar" class="round_bottom">
                <label>&lt;?php echo form_checkbox('remember', '1', FALSE);?&gt;Auto-login in future.</label>
                <a href="#">Forgot your password?</a>
            </div>        
            &lt;?php echo form_close();?&gt;
        </div>
#2

[eluser]toopay[/eluser]
Of course, because you don't use it!
Code:
<label class="fields"><strong>Username</strong></label>
&lt;?php echo form_error('email'); ?&gt;
&lt;?php echo form_input($email);?&gt;
#3

[eluser]austintbiggs[/eluser]
But I am using it!

See here:
Code:
...         else
        {  //the user is not logging in so display the login page
            //set the flash data error message if there is one
            $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

            $this->data['email'] = array('name' => 'email',
                'id' => 'email',
                'type' => 'text',
                'value' => $this->form_validation->set_value('email'),
            );
            $this->data['password'] = array('name' => 'password',
                'id' => 'password',
                'type' => 'password',
            );

            $this->load->view('body/login', $this->data);
        } ...

And here:
Code:
<div id="infoMessage">&lt;?php echo $message;?&gt;</div>
#4

[eluser]toopay[/eluser]
Code:
$this->data['message'] = function_exists('validation_errors') AND validation_errors() ? validation_errors() : $this->session->flashdata('message');
#5

[eluser]austintbiggs[/eluser]
This doesn't seem to work, when I replace

Code:
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

with
Code:
$this->data['message'] = ($this->form_validation->validation_errors()) ? $this->form_validation->validation_errors() : $this->session->flashdata('message');

I receive this error
Quote:Fatal error: Call to undefined method CI_Form_validation::validation_errors() in /controllers/body.php on line 59

when examining the document, line 59 is
Code:
$this->data['message'] = ($this->form_validation->validation_errors()) ? $this->form_validation->validation_errors() : $this->session->flashdata('message');

Any ideas?
#6

[eluser]toopay[/eluser]
Just test if the function exist
Code:
if(function_exists('validation_errors'))
{
   $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
}
else
{
   die('The function validation_errors() is unaccessible!');
}
#7

[eluser]austintbiggs[/eluser]
I tried that and now I'm receiving the following error
Quote:Fatal error: Call to undefined method CI_Form_validation::validation_errors() in /nfs/c07/h01/mnt/113668/domains/ravecity.tv/html/heart/controllers/body.php on line 61
#8

[eluser]toopay[/eluser]
Try the LAST code i gave.
#9

[eluser]Aken[/eluser]
If I had to guess, you're probably have one of two problems: 1) Your ternary IF statement, when it checks (validation_errors()) is returning true even when it's empty (which could be possible even if there's just a single space in the string). 2) Your flash data is empty.

I would var_dump() each of those items to see what sort of values they hold at various times, and go from there.
#10

[eluser]austintbiggs[/eluser]
Oh, my bad I put that in the view for some reason, I pieced it in, but still nothing. no errors, but nothing gets printed.




Theme © iAndrew 2016 - Forum software by © MyBB