Jump to content


This topic is now archived and is closed to further replies.


Help with Zend Form

Recommended Posts



I've been having a lot of trouble using Zend Form. The form validates just fine, but it's a real challenge to get it to display the form the way I'd like it to! I want to stay away from ViewScripts on this current project I'm working on. Here's what I want the form to display:

<form name="login" method="post" action="http://www.example.com">
	<legend>Step 1. Tell us about yourself</legend>	
	<div class="field-group">
		<label for="username">Username:</label>
		<input type="text" name="username" />

	<div class="field-group">
		<label for="password">Password:</label>
		<input type="password" name="password" />

               <div class="form-button-group">
	        <input type="submit" id="signup-button" name="submit" value="Create Account" />


The above is a fairly simple login script. I've tried just about everything, including clearDecorators(), removeDecorator(), and creating a display group. I don't think I fully understand how to manipulate the Zend Forms. Here's my forms code:

class LoginForm extends Zend_Form

public function init()

	->setAttrib('id', 'loginForm');

	$this->addElement('text', 'username', array('label' => 'Username'));

	$this->addElement('password', 'password', array('label' => 'Password'));
		->addValidator('stringLength', TRUE, array(6))

	$this->addElement('submit', 'Login');

	$this->addDisplayGroup(array('username', 'password', 'Login'), 'loginForm');

	//Not sure what to do here to get my form to display the correct output


How would I be able to modify the decorators to give me the form layout shown above? Any help would be greatly appreciated :)


Just incase this helps, the code above produces the following html:


<form id="loginForm" enctype="application/x-www-form-urlencoded" action="/index/form/" method="post"><dl class="zend_form">
<dt> </dt><dd><fieldset id="fieldset-loginForm"><dl>
<dt><label for="username" class="required">Username</label></dt>
<input type="text" name="username" id="username" value="" /></dd>
<dt><label for="password" class="required">Password</label></dt>
<input type="password" name="password" id="password" value="" /></dd>
<dt> </dt><dd>
<input type="submit" name="Login" id="Login" value="Login" /></dd></dl></fieldset></dd></dl></form>

Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.