Welcome Guest, Not a member yet? Register   Sign In
Validation errors

I'm having trouble with form validation errors. I have a controller called blogin that loads blogin_view containing a login form.

The blogin index method loads blogin_view but there is another function called log_in to which the form action is directed. That contains form validation rules but when I click the login button with blank inputs, the view is simply reloaded with no validation errors showing.

Controller code is like this:

function log_in()
        if($this->form_validation->run() == false)
                //echo validation_errors();die();

View code is like this:

<?php echo form_open('blogin/log_in','');
        echo form_fieldset('Log-in to Blog Admin');
        echo form_label('Username','username');
        echo form_error('username');
        echo form_input('username','','id="username"');
        echo form_label('Password','password');
        echo form_input('password','','id="password"');
        echo form_submit('login','Login');
        echo form_close(); ?>
        &lt;?php echo validation_errors('<p class="error">'); ?&gt;

In the log_in method is a commented out line I used for testing. When it is uncommented, the validation errors do print so they are being created. They just don't print on the view. I'm thinking that maybe I'm losing the POST array on reloading the page but I can't see why that should be.

Can anyone suggest a fix?

Try this for showing u'r validation error...
&lt;?php echo validation_errors('<div class="error">', '</div>'); ?&gt;

I think the validation_errors() method has to be called within the form. Try putting it before form_close() and see what happens.

echo validation_errors('<p class="error">');
echo form_close(); ?&gt;

[quote author="mi6crazyheart" date="1310080824"]Try this for showing u'r validation error...
&lt;?php echo validation_errors('<div class="error">', '</div>'); ?&gt;

You're right, you should specify a suffix if you are going to set a prefix, but in your case it should still be generating valid HTML because the default suffix is a closing paragraph tag. You could actually remove the prefix as well because the default prefix is the same as what you are setting it to.

From the form validation library:

var $_error_prefix            = '<p class="error">';
var $_error_suffix            = '</p>';

Thanks to all for your helpful replies from which I learnt although the problem turned out to be different. I had the wrong filepaths for the css links and a number of scripts and images so the structure of the page was completely shot. When I corrected that, it all came together and worked.

base_url() to the rescue!

Theme © iAndrew 2016 - Forum software by © MyBB