Zend Framework Login System Step by Step Tutorial - Part 2: To build login system, we need login form. In this post, we will learn how to build simple login form.
First, create a file named "loginform.phtml" within application/views/scripts/user. Enter following code:
<? include "header.phtml"; ?>
<h1><?=$this->escape($this->title);?></h1>
<form method='post' action='<?=$this->escape($this->action);?>'>
<table>
<tr>
<td><?=$this->escape($this->username);?></td>
<td><input type='text' name='username'></td>
</tr>
<tr>
<td><?=$this->escape($this->password);?></td>
<td><input type='password' name='password'></td>
</tr>
</table>
<input type='submit' name='login' value='Login'>
</form>
<? include "footer.phtml"; ?>
Next, create loginformAction at controller. Open your UserController.php within application/controllers. Add following loginFormAction() method:
public function loginFormAction()
{
$request = $this->getRequest();
$this->view->assign('action', $request->getBaseURL()."/user/auth");
$this->view->assign('title', 'Login Form');
$this->view->assign('username', 'User Name');
$this->view->assign('password', 'Password');
}
This form send two parameter: username and password. They are sent to user/auth page.
Now, point your browser to http://localhost/test/zend/helloworld/web_root/user/loginform. You may get like this:

| Series this article: Zend Framework Login: Preparing Database Zend Framework Login: Creating Form Login Zend Framework Login: Creating Authentication Zend Framework Login: Fatal error Cannot use object of type stdClass as array Zend Framework Login: Protected Page Zend Framework Login: Creating Logout Zend Framework Login: Creating Switching for Front Page advertisements blog comments powered by Disqus |

