[eluser]nevsie[/eluser]
I have created a simple view and controller for username and password basic checks. At this stage i am just requiring the two fields, nothing complicated.
When i first load the page i get an error "Undefined property: username" which relates to the "$this->validation->username" part i load in as the input field value. ignoring this as i kind of expect this error seeing as there is no value that has been validated yet!!!
My main point and query at this stage is that in the controller i have set_fields for username and password, yet when i dump the $this array and dig through the relevant part, the validation _fields array is empty? Is this correct? I would expect it to have somehting in their either on refresh, or form being submitted.
Similarly, no matter what i do the validate error_string never gets a value into it. So even though i say required, and validation detects FALSE, no error string is returned?
i have tried a few things from the forums with no success... so i am guessing there is soehting i have just overlooking with my inexperience. Hop you can help.
Code:
<?php
class Login extends Controller {
function Login()
{
parent::Controller();
$this->load->library('validation');
$this->load->helper('form');
}
function index()
{
$login_form_fields = array
(
'username' => 'Username',
'password' => 'Password'
);
$this->validation->set_fields($login_form_fields);
$login_form_rules = array
(
'username' => 'required',
'password' => 'required'
);
$this->validation->set_rules($login_form_rules);
if ($this->validation->run() == FALSE)
{
$this->load->view('admin/login');
}
else
{
redirect('user');
}
}
}
?>
Code:
<h1>Login</h1>
<?php echo $this->validation->error_string; ?>
<? echo form_open('login'); ?>
<p>Login Details</p>
<p>Username:<br /><? echo form_input(array('name' => 'username', 'id' => 'username', 'value' => $this->validation->username)); ?></p>
<p>Password:<br /><? echo form_input(array('name' => 'password', 'id' => 'password')); ?></p>
<p><? echo form_submit('submit', 'Submit'); ?></p>
<? echo form_close(); ?>
<pre>
<? print_r($this); ?>
</pre>