【问题标题】:Insert custom HTML into Zend_Form将自定义 HTML 插入 Zend_Form
【发布时间】:2012-06-26 21:05:11
【问题描述】:

我有一个从这样的控制器创建的 Zend_Form:

        $form = new Zend_Form;
        $form->setAction('/ad/add')->setMethod('post')->setAttrib('id', 'add_form');
        $form->addElement('text', 'name', array(
            'label' => 'Name',
            'description' => 'Ex.: Samsung Galaxy Tab 10.1',
            'validators' => array(
                'alnum',
                'notEmpty',
                array('stringLength', array('min' => 3, 'max' => 150))
            ),
            'required' => true
        ));
        $form->addElement('textarea', 'description', array(
            'label' => 'Description',
            'description' => 'Make sure you give an accurate description of your item.',
            'validators' => array(
                'alnum',
                'notEmpty',
                array('stringLength', array('min' => 10, 'max' => 255))
            ),
            'required' => true
        ));
        $form->addElement('submit', 'Submit');

当我从视图中输出它时,它工作得很好,被 dl 和 dd 魔法渲染。

我现在想要的是在这个表单中添加一个 ajax 图片上传功能。每张图片都将通过 ajax 上传,显示在 div 中,然后我的表单中的隐藏字段将填充上传文件的 ID。我怎样才能实现这一点,同时将图像上传位放在我的表单标记中?

【问题讨论】:

标签: zend-framework zend-form image-uploading zend-form-element ajax-upload


【解决方案1】:

使用视图脚本装饰器。我假设您必须通过 iframe 上传图片。您可以将其放在视图脚本装饰器的 phtml 文件中。

在你的表单类里面做。

$dec = new Zend_Form_Decorator_ViewScript();
$dec->setViewScript('Form.phtml');

$this->setDecorators(array($dec,'form'));

在 Form.phtml 中渲染元素做

<?php echo $this->element->username ;?>
<?php echo $this->element->image ; ?>

并按原样添加您的 iframe。

了解更多关于视图脚本装饰器

http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.viewScript

【讨论】:

  • 实际上,我将使用可用的 jQuery 插件之一上传图像。我需要的是显示上传图像的容器和上传插件拾取和使用的输入字段。我希望这个在我的表格中间。
  • @Zorrocaesar 把它放在你的表单中间,只需使用我上面提到的viewscipt装饰器。
  • 比它接缝我不明白你的答案。 Form.phtml 应该包含什么?主要形式,还是新的装饰器标记?看看我的示例代码?我应该如何将您的答案与我的代码结合起来?
  • 它将包含你通常放在
    标签中的 html 结构。 framework.zend.com/manual/en/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-14
  • 2018-09-18
  • 2021-07-27
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 2018-04-18
相关资源
最近更新 更多