在产品表单中我有一个带知识的选择字段,换句话说:要求安装此产品的知识。但是有一段时间,要求提供两种不同的知识。我用jquery做了这个,所以我克隆了表单中的select字段。但克隆后,选择字段具有相同的ID /名称。我尝试使用带有[]的名称的数组通知,但ZF不接受这个。我该如何解决这个问题?关心安德烈
这里是表格
class BM_Form_AudProducts extends Zend_Form {
public function init(){
/*
* addElementPrefixPath() method which will apply the decorator to all form elements.
* However, addElementPrefixPath() method will work only when you have created elements using the form object.
* If you are instantiating your element directly, then use addPrefixPath() on each of your element
*/
$this->addPrefixPath('BM_Form_Decorator', 'BM/Form/Decorator', 'decorator');
$this->setName('frmAudProduct')->setMethod('post')->setAction('');
$category = new Application_Model_ProductCategory();
$category = $category->selectCategories();
$selCategory = new Zend_Form_Element_Select('selCategory');
$selCategory->setLabel('Category:')
->setRequired(true)->setMultiOptions($category)
->addValidator('NotEmpty',true,array('message' => 'Category is required!'));
$txtTitle = new Zend_Form_Element_Text('txtTitle');
$txtTitle->setLabel('Title:')
->setRequired(true)
->addValidator('NotEmpty', true, array('messages' => 'Title is required!'));
$txtAbbr = new Zend_Form_Element_Text('txtAbbr');
$txtAbbr->setLabel('Abbreviation:')
->setRequired(true)
->addValidator('NotEmpty', true, array('messages' => 'Abbreviation is required!'))
->setIsArray(TRUE);
$txtDescription = new Zend_Form_Element_Textarea('txtDescription');
$txtDescription->setLabel('Description :')
->setAttrib('cols',40)
->setAttrib('rows',8);
$disposability = new Application_Model_Disposability();
$disposability = $disposability->selectDisposability();
$selDisposability = new Zend_Form_Element_Select('selDisposability');
$selDisposability->setLabel('Disposability:')
->setRequired(true)->setMultiOptions($disposability)
->addValidator('NotEmpty',true,array('message' => 'Dsiposability is required!'));
$knowledge = new Application_Model_Knowledge();
$knowledge = $knowledge->selectKnowledges();
$selKnowledge = new Zend_Form_Element_Select('selKnowledge');
$selKnowledge->setIsArray(TRUE);
$selKnowledge->setLabel('Knowledge team:')
->setRequired(true)->setMultiOptions($knowledge)
->addValidator('NotEmpty',true,array('message' => 'Knowledge is required!'))
->setDescription('<a href="#" id="duplicateKnw">Add another Team</a>')
;
$txtValidFrom = new Zend_Form_Element_Text('txtValidFrom',array('class' => 'datepicker'));
$txtValidFrom->setLabel('Valid from:')
->addValidator('Date');
$txtValidTo = new Zend_Form_Element_Text('txtValidTo',array('class' => 'datepicker'));
$txtValidTo->setLabel('Valid to:')
->addValidator('Date');
$chkActive = new Zend_Form_Element_Checkbox('chkActive');
$chkActive->setLabel('Active?');
$idProduct = new Zend_Form_Element_Hidden('idProduct');
$btnSubmit = new Zend_Form_Element_Submit('btnSubmit');
$btnSubmit->setLabel('')->setValue('Submit')->setOptions(array('class' => 'big-button'));
//add the elements to the form
$this->addElements(array($selCategory,$btnSubmit,$txtTitle,$txtAbbr,$txtDescription,$selKnowledge,$selDisposability,$txtValidFrom,$txtValidTo,$chkActive,$idProduct));
$this->setElementDecorators(array('Member'));
}
}
元素与jquery重复
答案 0 :(得分:1)
$selectElement->setIsArray(true);
它可以解决您的问题。