2012-04-20 11 views
0

こんにちは私はzend形式のマルチチェックボックスを使用しています。Zend Formマルチチェックダイナミック

私は 'id' 'name' 'surname' 'address'と 'city'というユーザーのリストを持っている$配列を持っています。私は名前+姓beetwen選択+ +都市を追加し、選択した名前と姓のIDをのcontrolerに復帰可能なチェックボックスを作成する必要が ...

ここでは私のフォームです:

class Application_Form_MultiplaSelezione extends Zend_Form 
{ 
public function init() 
{ 
    /* Form Elements & Other Definitions Here ... */ 
} 

public function selezione($array){ 
    $this->setMethod('post');  
    $count=count($array);  
    $multipla=new Zend_Form_Element_MultiCheckbox('scelta');   
    for($i=0;i<$count;$i++){    
     foreach ($array[$i] as $chiave=>$valore){ 
      if($chiave=='idnomeutente'){ 
       $nomeutente=$valore; 
      } 
      if($chiave=='nome'){ 
       $nome=$valore; 
      } 
      if($chiave=='cognome'){ 
       $cognome=$valore; 
      } 
      if($chiave=='indirizzo'){ 
       $indirizzo=$valore; 
      } 
      if($chiave=='residenza'){ 
       $residenza=$valore; 
      } 

     } 
     $val=$nome.' '.$cognome.' '.$indirizzo.' '.$residenza; 
     $multipla->addMultiOption($nomeutente, $val); 


     if($i==0){ 
      $iduser=$nomeutente; 
     } 
    } 

    $multipla->setValue($iduser); 

    $submit= new Zend_Form_Element_Submit('submit'); 
    $submit->setLabel('Seleziona'); 

    $this->addElements(array($multipla,$submit));   
} 
    } 

なぜ機能しないのですか?あなたは、モデルとコントローラでいくつかの変更を追加する必要があります。このコードに

<?php 

class Application_Form_MultiplaSelezione extends Zend_Form 
{ 
public function init() 
{ 
    $this->setMethod('post'); 

    $multipla=new Zend_Form_Element_MultiCheckbox('scelta'); 
    $multipla->setMultiOptions($this->getOptionsToMultipla()); 

    /* some other fields */ 

    $this->addElements(array(
     $multipla, 
     /* others fields */ 
     )); 
} 

public function getOptionsToMultipla() 
{ 
    /* there you can use static or dinamic method which: 
     1. select data from table 
     2. in foreach remake rows to your form, and add it to array ($array[] = "your string";) 
     3. return $array; 
     TIP: you should make other array where you have id of the rows, with it you can decode the request (compare index given from form) 
     (if you have problem with it I can help you in other thread :)*/ 

    /* for example of static method */ 
    return Your_Model::getOptionsToMultipla(); 
} 

+0

あなたのコードは不明です、あなたの予想される出力は正確ですか? '$ array'には何が入っていますか? 「選んだ名前と姓のIDをコントローラに返す」とはどういう意味ですか? – Liyali

+0

また、「なぜうまくいかないのか」というのは、泥棒に尋ねるのに良い質問です。ここでは、ほとんどの人がまずエラーを読む際の質問に答えることができます。何がうまくいかない? – Liyali

+0

私は配列にID名の姓名と市区町村のユーザのリストがあると書いています。私は、すべての要素のリストを持つmulticheck要素を持っていたいと思います。そのidを選択したいと思います。私はページが何も表示されず、ブラウザが何かを読み込むのを続けるとしようとすると動作しないと言います... – Simone

答えて

0

はこれを読んで理解してください。幸運:)

+0

ブラウザが動作していなかった問題は何か分かりました。しかし、今私は奇妙な問題があります。配列の情報に到達するコード(私のコードで表現されています)は機能しません。コントローラーのアクションで同じ配列を使って同じコードを使用するので、これは奇妙です。私はフォームでこれを使用していますが、私は同じだと思いますが、コードは動作しません....ブラウザログは次のとおりです:警告:foreach()の引数が無効です...それは別の投稿を開くより良いです.. – Simone

+0

それを変更してみてくださいhttp://pastebin.com/YTNXQgJb:http://pastebin.com/3wfa7BdRもし$ valore.cognomがエラーを出したら$ valore ['cognom'] –

+0

私は問題が別のものであることを発見します... $ this - > _ helper->リダイレクタ( 'action'、 'controller'、NULL、array( 'array' => $アレイ));リダイレクタがうまくいけないようです... – Simone