[eluser]OwanH[/eluser]
Sorry to say but your code isn't going to work. Browsers do *not* pass form elements to the script specified in the action parameter as URL segments, they pass them as query string values, and that's only if you use the GET method, and by default the
form_open helper function sends data using POST method. For your username and password to be passed to your login method they have to be passed as URL segments, which like I said your form will not do. Also there a some syntax errors in your markup and PHP blocks. I've modified your code (and made it slightly more compact) to work the way you want so here it is:
Your main controller:
Code:
<?php
class Main extends Controller {
function Main()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
}
function index()
{
$data = array('title' => 'My Blog Title', 'heading' => 'My Blog Heading');
$this->load->view("main_index_view", $data);
}
function login()
{
$username = $this->input->post('username') ? $this->input->post('username')
: 'default';
$password = $this->input->post('password') ? $this->input->post('password')
: 'default';
$login_data = array('title' => 'Login Page', 'username' => $username,
'password' => $password);
$this->load->view("main_login_view", $login_data);
}
}
?>
Your login form view:
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'>
<?=form_open('main/login');?>
Username:<input type='text' name='username' id="username" /><br />
Password:<input type='password' name='password' id="password" />
<input type='submit' name='Login' value='Login' />
</form>
</td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor='#CCCCCC'> </td>
</tr>
</table>
</body>
</html>
Your login page view:
Code:
<head>
<title><?=$title?></title>
</head>
<body>
<?php echo "You are trying to log in with:<br><br>username: $username<br>password: $password"; ?>
<body>
</body>
</html>
And good luck with your learning curve. Just be sure to study the CI documentation thoroughly and have a good understanding of the PHP language, syntax, contructs and functions as well (the PHP manual can be a PHP developer's best friend).