1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| <?php
class Application_Form_Voeux extends Zend_Form
{
protected $_clients = array();
public function init()
{
$this->setName('clientVoeux');
foreach ($this->_clients as $key => $client) {
// Le nom
$nom = new Zend_Form_Element_Text('nom[$key]');
$nom->setLabel('Nom:')->setValue($client['nom']);
// Le prénom
$prenom = new Zend_Form_Element_Text('prenom[$key]');
$prenom->setLabel('Prénom:')->setValue($client['prenom']);
// Liste des voeux (oui ou non)
$listVoeuxOptions = array(
'oui' => 'oui',
'non' => 'non'
);
$voeux = new Zend_Form_Element_MultiCheckbox('voeux[$key]');
$voeux->setLabel('Liste des voeux');
$voeux->setMultiOptions($listVoeuxOptions);
// Ajouter les éléments au subForm
$subForm = new Zend_Form_SubForm();
$subForm->addElements(array(
$nom,
$prenom,
$voeux
));
// Ajouter le subForm au Form
$this->addSubForms($subForm, 'subform[$key]');
}
// Ajouter le submit après la boucle
$this->addElement('submit', 'submit', array(
'label' => 'Mise à jour',
));
}
// Le set de ma variable tableau
public function setClients($clients)
{
$this->_clients = (array) $clients;
return $this;
}
} |
Partager