Reputation: 366
I'm trying to create a form in ZF 1.Here's my form class
class Application_Form_Album extends Zend_Form
{
public function init()
{
$this->setName('album');
#artist
$artist = new Zend_Form_Element_Text('artist');
$artist->setLabel('Artist')->setRequired(true)->addValidator('NotEmpty');
#title
$title = new Zend_Form_Element_Text('title');
$title->setLabel('Title')->setRequired(true)->addValidator('NotEmpty');
#submit
$submit = new Zend_Form_Element_Submit();
$submit->setAttribute('id','submitbutton');
$this->addElements(array($artist,$title,$submit));
}
}
and my controller action
public function addAction()
{
$form = new Application_Form_Album();
$form->submit->setLabel('Add');
$this->view->form = $form;
}
and my add.phtml
<?php echo $this->form;?>
But I'm getting this error.
Message: Zend_Form_Element requires each element to have a name
Not sure what I missed.Could anyone help me?
Upvotes: 1
Views: 326
Reputation: 506
You should give a name
for each form element. Missing name of submit. Zend Form generate id
and name
html tags from given name
For example:
$submit = new Zend_Form_Element_Submit('submitbutton');
And remove
$submit->setAttribute('id','submitbutton');
line.
Upvotes: 1