【问题标题】:Using array notations for form elements names in Zend_Form在 Zend_Form 中为表单元素名称使用数组表示法
【发布时间】:2010-11-12 12:10:12
【问题描述】:

在我在 Zend Framework 项目上使用 Zend_Form 构建的表单中,我需要有可变数量的文本区域。我需要将它们与数组表示法一起发布,以便我可以使用它们。

如果没有 Zend_Form,这很容易在文本区域的名称中添加方括号:

<textarea name="mytext[]">one</textarea>
<textarea name="mytext[]">two</textarea>

我无法使用 Zend_Form 完成此操作:

$t = new Zend_Form_Element_Textarea("mytext[]");
$t->setValue("one");
$myForm->addElement($t);
$t = new Zend_Form_Element_Textarea("mytext[]");
$t->setValue("two");
$myForm->addElement($t);

两个文本区域在视图中呈现,名称属性设置为“mytext”。

在这种情况下如何使用数组表示法?

【问题讨论】:

标签: php zend-framework zend-form


【解决方案1】:

如果要添加不可预知个数的textarea,我觉得应该使用sub_forms

$subForm = new Zend_Form_SubForm();
$subForm->addElement(....);

$form->addSubForm($subForm, 'subform');

Zend_Form (Sub Form)

问候。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多