Zend Framework Database: Creating Input Form
Zend Framework Database Step By Step Tutorial - Part 2: First step, we will create a form for inputing data. We create this form at User Controller. We just add method named "registerAction" as action for this controller.
Open "UserController.php" within application/controllers. Add following method:
public function registerAction()
{
$request = $this->getRequest();
$this->view->assign('action',"process");
$this->view->assign('title','Member Registration');
$this->view->assign('label_fname','First Name');
$this->view->assign('label_lname','Last Name');
$this->view->assign('label_uname','User Name');
$this->view->assign('label_pass','Password');
$this->view->assign('label_submit','Register');
$this->view->assign('description','Please enter this form completely:');
}
As we know, if we create action name "registerAction", we must create a view named "register.phtml". Ok, create a file named "register.phtml" within application/views/scripts/user. Enter following code:
<? include "header.phtml"; ?>
<h1><?=$this->escape($this->title);?></h1>
<div id="description">
<?=$this->escape($this->description);?>
</div>
<form name="register" method="post" action="<?=$this->escape($this->action)?>">
<table>
<tr>
<td><?=$this->escape($this->label_fname)?></td>
<td><input type="text" name="first_name"></td>
</tr>
<tr>
<td><?=$this->escape($this->label_lname)?></td>
<td><input type="text" name="last_name"></td>
</tr>
<tr>
<td><?=$this->escape($this->label_uname)?></td>
<td><input type="text" name="user_name"></td>
</tr>
<tr>
<td><?=$this->escape($this->label_pass)?></td>
<td><input type="password" name="password"></td>
</tr>
</table>
<input type="submit" name="submit" value="<?=$this->escape($this->label_submit);?>">
</form>
<? include "footer.phtml"; ?>
Point your browser to http://localhost/test/zend/helloworld/web_root/user/register

