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

[eluser]Perkin5[/eluser]
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:

Code:
function log_in()
    {
        $this->form_validation->set_rules('username','Username','required');
        $this->form_validation->set_rules('password','Password','required');
        if($this->form_validation->run() == false)
            {
                //echo validation_errors();die();
                $this->load->view('blogin_view');
                
            }

View code is like this:

Code:
<?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?
#2

[eluser]mi6crazyheart[/eluser]
Try this for showing u'r validation error...
Code:
&lt;?php echo validation_errors('<div class="error">', '</div>'); ?&gt;
#3

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

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

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

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:

Code:
var $_error_prefix            = '<p class="error">';
var $_error_suffix            = '</p>';
#5

[eluser]Perkin5[/eluser]
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