我正在使用zend form multicheckbox。
我有一个$数组,其中我有一个'id''name''surname''address'和'city'的用户列表。 我需要创建一个复选框,我可以选择beetwen name + surname + add + city并返回控制器名称和姓氏的ID ...
这是我的表格:
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));
}
}
为什么不起作用?
答案 0 :(得分:0)
尝试阅读并理解:
<?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();
}
对于此代码,您必须在模型和控制器中添加一些更改。祝你好运:)