こんにちは私は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();
}
:
あなたのコードは不明です、あなたの予想される出力は正確ですか? '$ array'には何が入っていますか? 「選んだ名前と姓のIDをコントローラに返す」とはどういう意味ですか? – Liyali
また、「なぜうまくいかないのか」というのは、泥棒に尋ねるのに良い質問です。ここでは、ほとんどの人がまずエラーを読む際の質問に答えることができます。何がうまくいかない? – Liyali
私は配列にID名の姓名と市区町村のユーザのリストがあると書いています。私は、すべての要素のリストを持つmulticheck要素を持っていたいと思います。そのidを選択したいと思います。私はページが何も表示されず、ブラウザが何かを読み込むのを続けるとしようとすると動作しないと言います... – Simone