问题描述
我有一个通过这样的控制器创建的Zend_Form:
I have a Zend_Form created from a controller like this:
$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 magic进行渲染.
When I output that from the view, it works just fine, being rendered with dl and dd magic just as it should.
我现在想要的是在此表单中添加ajax图片上传功能.每个图像都将由ajax上传,并显示在div中,然后将使用已上传文件的ID填充表单中的隐藏字段.在将图片上传位放在表单标记内部的同时,我该如何实现?
What I want now is to add an ajax image upload feature to this form. Each image will be uploaded by ajax, displayed in a div, and then a hidden field from my form will be populated with IDs of uploaded files. How can I achieve this, while having the image upload bits INSIDE my forms's markup?
推荐答案
使用视图脚本装饰器.我认为您必须通过iframe上传图像.您可以将其放置在视图脚本装饰器的phtml文件中.
Use view script decorator . I assume you must be uploading image through an iframe . Which you can place it inside the phtml file of your view script decorator.
在表单类内部执行操作.
Inside your form class do .
$dec = new Zend_Form_Decorator_ViewScript();
$dec->setViewScript('Form.phtml');
$this->setDecorators(array($dec,'form'));
在Form.phtml内呈现元素
Inside Form.phtml to render element do
<?php echo $this->element->username ;?>
<?php echo $this->element->image ; ?>
并按原样添加您的iframe.
and add your iframe as it is.
要了解有关查看脚本装饰器"的更多信息
To know more about View script decorator
这篇关于将自定义HTML插入Zend_Form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!