我的 Zend Form 有奇怪的行为。用“选择”按钮填充的字段在数据库中保持为空(NULL),其中一个字段的值放在另一个字段中。这是我的代码:
public function init()
{
$this->setName('projet');
$id = new Zend_Form_Element_Text('codeProjet'); //works great
$id->setLabel('Code du Projet');
$nomproj = new Zend_Form_Element_Text('nomProjet'); //is filled with the codeEntreprise value
$nomproj->setLabel('Nom du Projet')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim');
$deb = new Zend_Form_Element_Text('dateDebut'); //works great
$deb->setLabel('Date du début')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim');
$fin = new Zend_Form_Element_Text('dateFin'); //works great
$fin->setLabel('Date de fin')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim');
$montant = new Zend_Form_Element_Text('montantPrevu'); //works great
$montant->setLabel('Montant prévu')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim');
$chef = new Zend_Form_Element_Select('matriculeChef'); //remains empty
$options=array('select'=>'[select]');
$chef->setLabel('Chef de Projet')
->setRequired(true);
$boss = new Application_Model_DbTable_Developpeur();
foreach($boss->fetchAll() as $p)
$options[$p['matricule']]=$p['prenom'].' '.$p['nom'];
var_dump($options);
$chef->addMultioptions($options);
$chef->setValue($selected);
$boite = new Zend_Form_Element_Select('codeEntreprise'); //remains empty
$option=array('select'=>'[select]');
$boite->setLabel('Nom de l\'entreprise');
$entr = new Application_Model_DbTable_Entreprise();
foreach($entr->fetchAll() as $p)
$option[$p['codeEntreprise']]=$p['nom'];
var_dump($option);
$boite->addMultioptions($option);
$envoyer = new Zend_Form_Element_Submit('envoyer');
$envoyer->setAttrib('id', 'boutonenvoyer');
$this->addElements(array($id, $nomproj,$deb,$fin,$montant,$chef,$boite, $envoyer));
}
您是否知道为什么一个字段填充了错误的值,以及为什么有些字段在数据库中仍然为空?谢谢。