我希望这是一个快速回答的问题。我正在使用 开发一个表单Zend_Form
,我有一些Zend_Dojo_Form_Element_Textboxs
动态添加到这个表单中。
这些是从数据库中的行添加的,例如
$count = 0;
//we now loop through the skill types and add them to the form.
foreach($skillResult as $skill){
$skillTextBox = new Zend_Dojo_Form_Element_ValidationTextBox('skill-'.$count,
array('trim' => true,
'NotEmpty' => true,
'invalidMessage' => 'This can not be blank'
)
);
$skillTextBox->addValidator('NotEmpty')
->removeDecorator('DtDdWrapper')
->removeDecorator('HtmlTag')
->removeDecorator('Label');
//add the element to the form.
$myForm->addElement($skillTextBox);
$count++;
}
然后表单显示在一个视图脚本中,但是我需要提取它。由于我不知道表单中存在多少“技能”文本框,我不确定如何循环并将它们添加到视图脚本中。我通常会通过以下方式将它们添加到 viewScript 中:
<?php foreach($this->element->getElement('skill') as skill) :?>
<tr>
<td><?php echo $skill;?></td>
</tr>
<?php endforeach;?>
但是我收到警告错误消息:为 foreach() 提供的参数无效
我是以一种倒退的方式来解决这个问题并改变我对这种形式的处理方式,还是我在这里遗漏了什么?
提前致谢...