Jump to content

Help with Zend Form


milesap

Recommended Posts

Hello,

 

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">
<fieldset>
	<legend>Step 1. Tell us about yourself</legend>	
	<div class="field-group">
		<label for="username">Username:</label>
		<input type="text" name="username" />
	</div>

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

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

 

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:

<?php 
class LoginForm extends Zend_Form
{

public function init()
{

	$this->setAction('/index/form/')
	->setMethod('post')
	->setAttrib('id', 'loginForm');

	$this->addElement('text', 'username', array('label' => 'Username'));
	$this->getElement('username')
		->addValidator('alnum')
		->setRequired(true)
		->addFilter('StringTrim');

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

	$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>
<dd>
<input type="text" name="username" id="username" value="" /></dd>
<dt><label for="password" class="required">Password</label></dt>
<dd>
<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.