0

I'm following along with a tut the source files can be found here: https://github.com/JeffreyWay/Simple-CI-Authentication

Now when I try and login it keeps looping back saying I have errors where as in the tutorial video his comes back as ok and no errors shown.

I get The Email Address field is required.The Password field is required.

Even though I have entered input for both fields which is valid here is my code:

application/controllers/admin.php

<?php if(! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends CI_Controller
{
    public function index()
    {
        $this->load->library('form_validation');
        $this->form_validation->set_rules('email_address', 'Email Address', 'required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required|min_length[4]');

        if ($this->form_validation->run() !== FALSE)
        {
            $this->load->model('Admin_model');
            $this->Admin_model->verify_user('[email protected]', 'test');
            // then validation passed. get from the db.
        }

        $this->load->view('login_view');
    }
}

application/views/login_view.php

<h1>Login</h1>

<?php echo form_open('admin'); ?>
<p>
    <?php 
        echo form_label('Email Address: ', 'email_address');
        echo form_input('Email Address', '', 'id="email_address"');
    ?>
</p>
<p>
    <?php 
        echo form_label('Password: ', 'password');
        echo form_password('Password', '', 'id="password"');
    ?>
</p>
<?php echo form_submit('submit', 'Login'); ?>
<?php echo form_close(); ?>

<div class="errors"><?php echo validation_errors(); ?></div>

Any ideas?

1 Answer 1

1

You need to change the form inputs in the view to:

form_input('email_address', '', 'id="email_address"');

form_password('password', '', 'id="password"');

Their name must match the name you entered in the rules in the controller.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.