开发者

zend framework: select field with same name

in a product form I have a select field with knowledges, in other words : what knowledge is requested to install this product. Some time however, there are two different knowledges requested. I did this with jquery, so I clone the select field in the form. But the select fields have the same id/name after the clone. I tried using array notifications for the name with [], but ZF do not accept this. How may I solve this problem? Regards Andrea

here the form

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!'));

     $txtTi开发者_C百科tle = 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'));
}

}

the element is duplicated with jquery


$selectElement->setIsArray(true);

It can solve your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜