Insert custom HTML into Zend_Form

 ̄綄美尐妖づ 提交于 2019-12-12 03:30:05

问题


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');

When I output that from the view, it works just fine, being rendered with dl and dd magic just as it should.

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?


回答1:


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'));

Inside Form.phtml to render element do

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

and add your iframe as it is.

To know more about View script decorator

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



来源:https://stackoverflow.com/questions/11215914/insert-custom-html-into-zend-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!