2011-07-01 7 views
1

製品フォーム私はknowledgesという選択フィールドを持っています。つまり、この製品をインストールするにはどのような知識が必要ですか。しかし、しばらくの間、2つの異なる知識が要求されています。私はjqueryでこれを行いました。そのため、フォームの選択フィールドをクローンします。しかし、選択フィールドはクローンの後に同じID /名前を持ちます。私は[]で名前の配列通知を使用しようとしましたが、ZFはこれを受け付けません。どうすればこの問題を解決できますか?ここでよろしくアンドレアzend framework:同じ名前のフィールドを選択してください

要素は、それはあなたの問題を解決することができますjqueryの

答えて

1
$selectElement->setIsArray(true); 

と重複しているフォーム

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

}

+0

これをselectElementに追加しました。また、textElementを試しましたが、どちらの場合も動作していません。目的は以下のような要素を持つことです:name = "txtName []" – cwhisperer

+0

@cwhispererあなたのフォームとあなたの質問に関連するすべてのコードを教えてくれますか? – pltvs

+0

あなたの助けてくれてありがとう、私は質問にフォームコードを追加しました... – cwhisperer

関連する問題