2011-07-01 45 views
1

產品形式我有一個選擇領域知識,換言之:什麼知識要求安裝此產品。然而,有些時候,有兩種不同的知識要求。我用jQuery做了這個,所以我克隆了表單中的select字段。但是克隆之後,選擇字段具有相同的id /名稱。我試着用[]的名字使用數組通知,但ZF不接受這個。我該如何解決這個問題?問候安德烈zend框架:選擇同名產品

這裏的形式

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

回答

1
$selectElement->setIsArray(true); 

它可以解決你的問題。

+0

我已經將此添加到selectElement中,並嘗試使用textElement,並且在兩種情況下都不起作用。目標是有一個元素,如:名稱=「txtName []」 – cwhisperer

+0

@cwhisperer你可以給我你的形式和所有與你的問題相關的代碼? – pltvs

+0

謝謝你的幫助,我將表單代碼添加到問題中... – cwhisperer