Welcome Guest, Not a member yet? Register   Sign In
problem in simple login form : Message: Undefined property: CI_Validation::$username
#1

[eluser]bhakti.thakkar[/eluser]
Just a day old in CI.

Code in login_view.php

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;

&lt;base href="&lt;?php echo $this-&gt;config->item('base_url') ?&gt;application/myapp/" />
&lt;link rel="stylesheet" type="text/css"  href="&lt;?php echo "$base/$css"?&gt;"&gt;
&lt;title&gt;myapp&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<br>
<br>
<TABLE width="60%" align="center" border="0"cellpadding="0">
<TR>
    <TD align="left"><img src="images/logo.gif" Alt="Logo"/></TD>
</TR>
</table>

<TABLE align="center"width="60%" border="0" class="table" cellpadding="0">
<TR>
    <TD bgcolor="#DDEFFC" align="left" height="60px"><img src="images/logo.gif"></TD>
</TR>
<TR>
    <TD class="td">
    <table width="100%" cellpadding=8>
    <tr>
        <td class=td>
        <ul>
            <li>This page should be used by authorized users of the company and their registered users.
            <li>If you have been granted access to this system, please enter your Login Name and Password. Unauthorized access is strictly prohibited</li>
    
    </td>
    </tr>
    </table>
</TD>
</TR>
<TR>

    <TD class="td">
    <TABLE cellpadding="4" width="100%">

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

&lt;?php echo form_open('form'); ?&gt;
    <tr>
        <td colspan='2' class=mainheadertd>Login...</td>
    <TR>
        <TD bgcolor="#E6F3FD" class=td width="12%"><FONT SIZE="2" COLOR="">Username</FONT></TD>
        <TD class=td>&lt;input type="text" name="username" value="&lt;?=$this-&gt;validation->username;?&gt;" /> </td>
    </tr>

    <TR colspan="2">
        <TD bgcolor="#E6F3FD" ><FONT SIZE="2" COLOR="">Password</TD>
        <TD class=td>&lt;input type="text" name="password" value="" /&gt;
        &lt;input type="submit" value="Submit" /&gt;
        &lt;input title="Click here to login" type="image"title="Submit" src="images/btnLogon.gif" height="25" class="subbutton"/&gt;&nbsp;&nbsp;&nbsp;<A title="Help" HREF="help/help.html#login"><IMG SRC="images/help.gif" BORDER="0" ALT="Help"></A>
    </tr>

&lt;/form&gt;

</table>
&lt;/body&gt;
&lt;/html&gt;

code in login.php

Code:
&lt;?php

class Login extends Controller {

    function Login()
    {
        parent::Controller();    
        $this->load->helper('url');

    }
    
    function index()
    {
        $data['base']       = $this->config->item('base_url');
        $data['css']        = $this->config->item('css');        
        
        $this->load->helper(array('form', 'url'));        // load form
        $this->load->library('validation'); // load validations

//          if ($this->input->post('mainform')) {
              $rules['username'] = 'required|trim';
              $rules['password'] = 'required|trim';


              $this->validation->set_rules($rules);
//            }

    
        if ($this->validation->run() == TRUE)
        {            
            $this->load->view('checkuser' , $data);


        }
        else
        {
            $this->load->view('login_view' , $data);
        }
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

As soon as i add &lt;input type="text" name="username" value="&lt;?=$this-&gt;validation->username;?&gt;" /> instead of &lt;input type="text" name="username" value="" /&gt; i get the error :Undefined property: CI_Validation. Also if i am leaving the fields blank, no serverside validation messages are displayed. where am i wrong
#2

[eluser]manilodisan[/eluser]
edited...sorry ...I thought I saw a pussycat Tongue
#3

[eluser]bhakti.thakkar[/eluser]
actually i think i am miss managing my application. the problem is i want handle multiple one CI folder and as i read somewhere i have put my folder for eg: foo under application folder and it has all the files and folders which the CI application folder has.


Below is the folder structure
applications
foo
config/
controllers/
errors/
helpers/
hooks/
languages
etc ... etc...

bar
system
user_guide
#4

[eluser]dbashyal[/eluser]
I got the same error and i work around like this

in controller:
Code:
function _validity($v)
    {
        if(isset($this->validation->$v))
        {
            return $this->validation->$v;
        }
        else
        {
            return '';
        }
    }

in View's field value:
Code:
echo $this->_validity('firstname');
#5

[eluser]Aken[/eluser]
You'll need some sort of IF check to see if $this->validation->field actually exists.

You also need to define the fields, as explained in the Validation Guide: http://ellislab.com/codeigniter/user-gui...ation.html See under 'Re-populating the form.'




Theme © iAndrew 2016 - Forum software by © MyBB