Welcome Guest, Not a member yet? Register   Sign In
form_error won't display in view
#1

[eluser]Zac G.[/eluser]
Hi,

I am having some trouble displaying the error messages using the form_validation class.

Here is my (simplified) controller

Code:
class Login extends Controller {

    function Login()
    {
        parent::Controller();    
        $this->load->library('form_validation');
        $this->load->model('Users_model');
    }
    
    function index()
    {
        $data['page_info'] = array('title'=>'Login');    
        $this->load->view('header_view', $data);
        $this->load->view('login_view');
    }
    
    function validate()
    {

        $config = array(
                                     array(
                                                 'field'   => 'username',
                                                 'label'   => 'Username',
                                                 'rules'   => 'trim|required'
                                            ),
                                     array(
                                                 'field'   => 'password',
                                                 'label'   => 'Password',
                                                 'rules'   => 'trim|required|md5'
                                            )
                                );
        
        $this->form_validation->set_rules($config);
    
        if ($this->form_validation->run() == FALSE)
        {
            $data['page_info'] = array('title'=>'Login');    
            $this->load->view('header_view', $data);
            $this->load->view('login_view');
        }
        else
        {
            echo "<h1>In.</h1>";
        }
    }

And the view

Code:
&lt;?= form_open('login/validate'); ?&gt;
                
                    <div class="field">                        
                        <label for="username">Username</label>
                        <p class="labelHint">Username is your student ID that you log onto school computers with.</p>
                        &lt;?
                                $data = array(
                                'name'        => 'username',
                                'id'          => 'username',
                                'class'       => 'text',
                                'value'                =>    set_value('username'),                            
                                );
                                echo form_input($data);
                        ?&gt;    
                        
                        &lt;?php echo form_error('username'); ?&gt;

                    </div>
                    <div class="field">
                        <label for="password">Password</label>
                        &lt;?
                                $data = array(
                                'name'        => 'password',
                                'id'          => 'password',
                                'class'       => 'text',
                                'type'                => 'password',
                                'value'                =>    set_value('password'),                            
                                );
                                echo form_input($data);
                        ?&gt;    
                        
                        &lt;?php echo form_error('password'); ?&gt;

                    </div>
                    
                    <div class="clearfix login-submit">
                        <span class="fleft">
                            <p><a href="#">Forget your password?</a></p>
                        </span>
                        <span class="fright">
                            <button class="button" type="submit"><strong>Log In</strong></button>
                        </span>
                    </div>
                
                &lt;?= form_close(); ?&gt;

The validation works, it just doesn't return the proper messages if the validation fails.

Thanks!
#2

[eluser]TheFuzzy0ne[/eluser]
Can you give an example of "improper" messages? It sounds like a really strange issue. [url="http://validator.w3.org/"]Is your markup valid[/url]?
#3

[eluser]Zac G.[/eluser]
Hi!

Yes, I had a nested p tag, but it validates now and I still don't get any error messages.

An improper message would be that I leave the input for password empty and it should say that password is a required field. But I get no such friendly reminder.
#4

[eluser]TheFuzzy0ne[/eluser]
You might want to check the HTML source in your browser; see if there are any errors that just aren't rendering properly. It's happened to me many times in the past.

Is you mark-up valid?
#5

[eluser]Zac G.[/eluser]
Thanks!

Unfortunately, it is valid ;p and nothing is popping out to me about other errors. What is odd is that the validation is working, just not the error reporting?

I appreciate your help
#6

[eluser]maicobreako[/eluser]
I'm having the exact same problem. I had no validation issues prior to 1.7.0. I've tried pasting the code in straight from the documentation and it still doesn't work properly. Bad download perhaps?

Currently using CI 1.7.1 on XP/wamp. Apache 2.2.8, PHP 5.2.9-1.

<edit>
Re-downloaded and replaced /system with no change in result. Remembered that I have matchbox installed, so I set up a virgin application and dropped the same files into it. Works like a charm now! I was really beginning to like matchbox too.
</edit>
#7

[eluser]TheFuzzy0ne[/eluser]
I'm just guessing here, but the only real difference with your code to the way I write mine, is that I use $rules for my rules array, not $config. I would recommend changing this, and seeing if it makes any difference.

If that doesn't work, I'll test the code on my server.
#8

[eluser]Zac G.[/eluser]
Alrighty! All set now. I did a full re-upload of the files and it's working like a charm now.

Thanks for your help!
#9

[eluser]maicobreako[/eluser]
Found the following thread/fix regarding matchbox and 1.7.x validation. Tried it successfully.
http://ellislab.com/forums/viewthread/95755/




Theme © iAndrew 2016 - Forum software by © MyBB