Welcome Guest, Not a member yet? Register   Sign In
noob - forms validation and set fields problem
#1

[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>

&lt;?php echo $this->validation->error_string; ?&gt;

&lt;? echo form_open('login'); ?&gt;
    <p>Login Details</p>
    <p>Username:<br />&lt;? echo form_input(array('name' => 'username', 'id' => 'username', 'value' => $this->validation->username)); ?&gt;</p>
    <p>Password:<br />&lt;? echo form_input(array('name' => 'password', 'id' => 'password')); ?&gt;</p>
    <p>&lt;? echo form_submit('submit', 'Submit'); ?&gt;</p>
&lt;? echo form_close(); ?&gt;

<pre>
&lt;? print_r($this); ?&gt;
</pre>


Messages In This Thread
noob - forms validation and set fields problem - by El Forum - 03-05-2008, 06:03 PM
noob - forms validation and set fields problem - by El Forum - 03-05-2008, 06:15 PM
noob - forms validation and set fields problem - by El Forum - 03-06-2008, 03:58 AM
noob - forms validation and set fields problem - by El Forum - 03-06-2008, 04:10 AM
noob - forms validation and set fields problem - by El Forum - 03-06-2008, 04:14 AM
noob - forms validation and set fields problem - by El Forum - 06-05-2008, 12:14 PM
noob - forms validation and set fields problem - by El Forum - 06-05-2008, 12:57 PM
noob - forms validation and set fields problem - by El Forum - 06-10-2008, 03:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB