2010年12月9日星期四

RE: [fw-mvc] Zend Form in two columns

Has the Zend Framework team ever thought of writing a ming component to add
to the library? Just wondering.

Thanks

Jimmy Sole

-----Original Message-----
From: Matthew Weier O'Phinney [mailto:matthew@zend.com]
Sent: Thursday, December 09, 2010 12:25 PM
To: fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] Zend Form in two columns

-- Thomas List <thomaslist@hotmail.com> wrote
(on Thursday, 09 December 2010, 12:13 PM -0500):
> I am trying to figure out how to develop a form with the form elements
> arranged in two columns.

Use sub forms and/or display groups. Both options allow you to group
elements -- you can then group the elements you want in each column in
separate sub forms or display groups, and use either decorators or CSS
to arrange them visually.

> I call the form from my the controller and I
> created the form class as follows:
>
> class Application_Form_Housing extends Zend_Form
> {
> public function init()
> {
> // Set the method for the display form to POST
> $this->setMethod('post');
>
> $id = new Zend_Form_Element_Hidden('id');
> $id->addFilter('Int');
> $this->addElement($id);
>
> $this->addElementPrefixPath('App_Validate',
'App/Validate/','validate');
>
>
> $this -> addElement( 'select', 'types', array(
> 'label' => '<h1>What type of home do you live in:</h1><br />',
> 'escape' => false,
> 'required' => true,
> 'multiOptions' => array('Existing Home' => 'Existing Home','New
Construction' => 'New Construction','Condominium' => 'Condominium',
> 'Apartment' => 'Apartment'),
> 'decorators' => array(
> 'ViewHelper',
> 'Errors',
> array( 'HtmlTag', array( 'tag' => 'dd' ) ),
> array( 'Label', array( 'tag' => 'dt', 'escape' => false) )
> )
> ));
>
> $this -> addElement( 'text', 'zip', array(
> 'label' => '<h1>What is your zipcode:</h1>',
> 'escape' => false,
> 'required' => true,
> 'validators' => array(
> array('validator'=>'ZipCodeExists'),
> array('validator' => 'StringLength', 'options' => array(
> 'min' => 5,
> 'max' => 5,
> 'messages' => array(
> Zend_Validate_StringLength::INVALID => 'Invalid Zip
code entered',
> Zend_Validate_StringLength::TOO_SHORT => 'Zip code
must be at least 5 characters',
> Zend_Validate_StringLength::TOO_LONG => 'Zip code
must not be more than 5 characters'
> )
> ))),
> 'decorators' => array(
> 'ViewHelper',
> 'Errors',
> array( 'HtmlTag', array( 'tag' => 'dd' ) ),
> array( 'Label', array( 'tag' => 'dt', 'escape' => false) )
> )
> ));
>
>
>
> // Add the submit button
> $this->addElement('submit', 'submit', array(
> 'ignore' => true,
> 'label' => 'submit',
> ));
>
> What would I need to do in the Form, or in the addElement fields to get
them to show up in two columns, rather than one long column? In order for
the submit button to recognize both fields, would that also require a
decorator or viewHelper? Any pointers to get me started out in the right
direction would be very helpful.
>
> Regards,
> Thomas
>

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

没有评论: