0

嗨,我正在使用 zend 表单多复选框。

我有一个 $array,其中有一个用户的 'id' 'name' 'surname' 'address' 和 '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));           
}
    }

为什么它不起作用???

4

1 回答 1

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

对于此代码,您必须在模型和控制器中添加一些更改。祝你好运 :)

于 2012-04-20T21:09:50.633 回答