phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Zend Framework Login: Creating Form Login

Tag: framework, zend, zend framework, authentication, Zend_Auth, Form, Login   Category: PHP Framework
post: 22 Apr 2008 read: 1,367


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

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

1 Responses to Zend Framework Login: Creating Form Login:

Just out of curiousity, why aren't you using Zend_Form for form creation? :-)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting