Welcome Guest, Not a member yet? Register   Sign In
Getting post data from a from...
#1

[eluser]kuysal[/eluser]
Hi I'm new to CI and currently on learning level. I'm trying to make a simple login page in which, information is sent by a form with a post method and to be taken as function parameter (This is the only way I know to pass the form elements in CI). Here is the view page I'm using:

Code:
<head>
<title><?=$title?></title>
</head>
<body>
<table width='848' border='0' align='center'>
  <tr>
    <td bgcolor='#E9E9E9'><table width='100%' border='0'>
      <tr>
        <td width='50%' bgcolor='#FFFFFF'><div align='center'><h1>Logo</h1></div></td>
        <td width='50%' bgcolor='#FFFFFF'>
          &lt;? echo form_open('main/login'); ?&gt;
          Username:&lt;input type='text' name='username' id="username" /&gt;
          <br />
          Password:&lt;input type='password' name='password' id="password" /&gt;
          &lt;input type='submit' name='Login' value='Login' /&gt;
        </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td bgcolor='#CCCCCC'>&nbsp;</td>
  </tr>
</table>
&lt;/body&gt;
&lt;/html&gt;

and here is my main controller which holds login function:

Code:
&lt;?php

class Main extends Controller {

    function Main()
    {
        parent::Controller();
        
        $this->load->helper('form');
        $this->load->helper('url');
    }
    
    function index()
    {        
        $data['title'] = 'My Blog Title';
        $data['heading'] = 'My Blog Heading';
        
        $this->load->view("main_index_view", $data);
    }
    
    function login($username = 'default', $password = 'default')
    {
        $login_data['title'] = 'Login Page';
        $login_data['username'] = $username;
        $login_data['password'] = $password;
        
        $this->load->view("main_login_view", $login_data);
    }
}
?&gt;

and finally that is my login view:

Code:
&lt;head&gt;
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;? echo 'You are trying to log in with the username : ' . $username;
echo '<br>And password : ' . $password;
?&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;

It always displays the default parameters. Parameters sent by form can't be taken. I've checked the code many times but it still doesn't work. As I've said I'm new to CI.

Please help...


Messages In This Thread
Getting post data from a from... - by El Forum - 07-11-2007, 11:51 AM
Getting post data from a from... - by El Forum - 07-11-2007, 12:06 PM
Getting post data from a from... - by El Forum - 07-11-2007, 12:15 PM
Getting post data from a from... - by El Forum - 07-11-2007, 12:24 PM
Getting post data from a from... - by El Forum - 07-11-2007, 12:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB