Zend Framework Login: Creating Form Login

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"; ?>
  <form method='post' action='<?=$this->escape($this->action);?>'>
	  <td><input type='text' name='username'></td>
	  <td><input type='password' name='password'></td>
  <input type='submit' name='login' value='Login'>
<? 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

Bookmark and Share Tag: framework, zend, zend framework, authentication, Zend_Auth, Form, Login Category: PHP Framework Post : April 22nd 2008 Read: 110,444


blog comments powered by Disqus