如何将zend表单元素添加到php中的表单中?

发布于 2025-01-08 15:09:29 字数 1066 浏览 0 评论 0原文

我的 zend 表单中有一个 foreach 循环,在本例中,$this->args[1]的计数为 5:

foreach ($this->args[1] as $val)
    {

        $submitImage = new Zend_Form_Element_Image('submit_image');
        $checkBox = new Zend_Form_Element_Checkbox('id_checkbox');

        $this->addElement( $submitImage ->setImage($val->full_path) );
        $this->addElement( $checkBox ->setValue($val->id) );
    }

我遇到的问题是 $submitImage 和 $checkBox 被覆盖,我只得到每个元素的一个元素,即最后一个元素。

有什么想法如何让它们全部出现吗?

谢谢

我也尝试过:

$i=0;
foreach ($this->args[1] as $val)
    {

        $submitImage = 'submitImage'.$i;
            $checkBox = 'checkBox'.$i;

        $submitImage = new Zend_Form_Element_Image('submit_image');
        $checkBox = new Zend_Form_Element_Checkbox('id_checkbox');

        $this->addElement( $submitImage ->setImage($val->full_path) );
        $this->addElement( $checkBox ->setValue($val->id) );
    $i++;
    }

但它不起作用

i have a foreach loop in my zend form, in this case the $this->args[1]has a count of 5 :

foreach ($this->args[1] as $val)
    {

        $submitImage = new Zend_Form_Element_Image('submit_image');
        $checkBox = new Zend_Form_Element_Checkbox('id_checkbox');

        $this->addElement( $submitImage ->setImage($val->full_path) );
        $this->addElement( $checkBox ->setValue($val->id) );
    }

the problem i encounter is that the $submitImage and $checkBox get overwritten and i only get one element of each, the last one.

any ideas how to make them all show up?

thanks

i've also tried:

$i=0;
foreach ($this->args[1] as $val)
    {

        $submitImage = 'submitImage'.$i;
            $checkBox = 'checkBox'.$i;

        $submitImage = new Zend_Form_Element_Image('submit_image');
        $checkBox = new Zend_Form_Element_Checkbox('id_checkbox');

        $this->addElement( $submitImage ->setImage($val->full_path) );
        $this->addElement( $checkBox ->setValue($val->id) );
    $i++;
    }

but it doesn't work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岛歌少女 2025-01-15 15:09:29

你真的很接近,只需要一些小的修复。任何使元素名称独一无二的东西。

foreach ($this->args[1] as $val)
    {

        $submitImage = new Zend_Form_Element_Image('submit_image'. $val->id);
        $checkBox = new Zend_Form_Element_Checkbox('id_checkbox' . $val->id);

        $this->addElement( $submitImage ->setImage($val->full_path) );
        $this->addElement( $checkBox ->setValue($val->id) );
    }

或者如果你喜欢

$i=0;
foreach ($this->args[1] as $val)
    {

        $image = 'submitImage'.$i;
            $box = 'checkBox'.$i;

        $submitImage = new Zend_Form_Element_Image($image);
        $checkBox = new Zend_Form_Element_Checkbox($box);

        $this->addElement( $submitImage ->setImage($val->full_path) );
        $this->addElement( $checkBox ->setValue($val->id) );
    $i++;
    }

Liyali 有权利,我只是更冗长:)

[编辑]
更正了第二个循环中的变量冲突。

your really close, only need minor fixes. Anything to make the name of the element unique.

foreach ($this->args[1] as $val)
    {

        $submitImage = new Zend_Form_Element_Image('submit_image'. $val->id);
        $checkBox = new Zend_Form_Element_Checkbox('id_checkbox' . $val->id);

        $this->addElement( $submitImage ->setImage($val->full_path) );
        $this->addElement( $checkBox ->setValue($val->id) );
    }

or if you like

$i=0;
foreach ($this->args[1] as $val)
    {

        $image = 'submitImage'.$i;
            $box = 'checkBox'.$i;

        $submitImage = new Zend_Form_Element_Image($image);
        $checkBox = new Zend_Form_Element_Checkbox($box);

        $this->addElement( $submitImage ->setImage($val->full_path) );
        $this->addElement( $checkBox ->setValue($val->id) );
    $i++;
    }

Liyali has the right of it I'm just more verbose :)

[EDIT]
corrected variable collision in second loop.

听风吹 2025-01-15 15:09:29

您的元素名称必须不同

 $submitImage = new Zend_Form_Element_Image($submitImage);
 $checkBox = new Zend_Form_Element_Checkbox($checkBox);

Your element names must be different.

 $submitImage = new Zend_Form_Element_Image($submitImage);
 $checkBox = new Zend_Form_Element_Checkbox($checkBox);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文