2008年9月16日星期二

Re: [fw-mvc] need help with Zend Form

Gabriel Baez-2 wrote:
>
> Hey guys, I just started messing around with zend_form and like it.
>
> I can't figure out how to set the content of a textarea I looked
> through the docs and mailing list and couldn't find an example this is my
> code.
> Any ideas?
>
>
>
> $software_id =
> Zend_Filter::get($this->getRequest()->get('softwareid'),'Int');
> $software = new Software();
> $result = $software->fetchRow($software->select()->where('SOFTWARE_ID
> =
> ?',$software_id));
> $form = new SoftwareForm();
> $form->name->setValue($result->SOFTWARE_NAME);
> $form->desc->textArea($result->SOFTWARE_DESC);
> $form->submit->setLabel('Edit');
> $form->published->addMultiOptions(array( 'Y' => 'Yes', 'N' => 'No'));
> $this->view->form = $form;
>
>
>
> Class:
>
>
>
> class SoftwareForm extends Zend_Form
> {
> public function __construct($options = null)
> {
> parent::__construct($options);
> $this->setName('addsoftware');
>
> $name = new Zend_Form_Element_Text('name');
> $name->setLabel('Software')
> ->setRequired(true)
> ->addFilter('StripTags')
> ->addFilter('StringTrim')
> ->addValidator('NotEmpty');
>
> $published = new Zend_Form_Element_Select('published');
> $published->setLabel('Published')
> ->setRequired(true)
> ->addFilter('StripTags')
> ->addFilter('StringTrim')
> ->addValidator('NotEmpty');
>
> $desc = new Zend_Form_Element_Textarea('description');
> $desc->setLabel('Description')
> ->setRequired(true)
> ->addFilter('StripTags')
> ->addFilter('StringTrim')
> ->addValidator('NotEmpty');
>
> $id = new Zend_Form_Element_Hidden('id');
>
> $submit = new Zend_Form_Element_Submit('submit');
> $submit->setAttrib('id', 'submitbutton');
>
> $this->addElements(array($id, $name, $published,$desc, $submit));
> }
> }
>
>

It's not just because you've specified the wrong element name is it?

// Currently
$form->desc->textArea($result->SOFTWARE_DESC);

// Correct
$form->description->setValue($result->SOFTWARE_DESC);

Also, it's recommended practice to override the (empty) init method in
Zend_Form rather than the constructor:

class SoftwareForm extends Zend_Form
{
public function init()
{
// Form initialisation as normal
}
}
--
View this message in context: http://www.nabble.com/need-help-with-Zend-Form-tp19512367p19513274.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: