down123321123 2012-09-04 14:31
浏览 34
已采纳

我想自定义zend表单的标记

I have a form and I would like to customise the markup for it. Im using the decorators at the bottom of the class. However, I keep getting the error:

Exception caught by form: No file decorator found.

I was wondering if someone would be able to show me an example. I basically want to output the form as and do away with the standard layout. Maybe add a few custom classes also.

Updated

class Application_Form_Admin extends Zend_Form
{

    public function init()
    {
        // Set the method for the display form to POST
        $this->setMethod('post');

        // set the data format
        $this->setAttrib('enctype', 'multipart/form-data');

        // Add the entry id
        $this->addElement('hidden', 'id', array(
            'required'   => false
        ));

        // Add the title
        $this->addElement('text', 'title', array(
            'label'      => 'Project Title',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the title
        $this->addElement('text', 'appid', array(
            'label'      => 'App Id',
            'required'   => true,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the title
        $this->addElement('text', 'appsecret', array(
            'label'      => 'App Secret',
            'required'   => true,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the title
        $this->addElement('text', 'namespace', array(
            'label'      => 'Namespace',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the title
        $this->addElement('text', 'applink', array(
            'label'      => 'App Link',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 255))
                )
        ));

        // Facebook Only?
        $this->addElement('checkbox', 'fbonly', array(
            'label'      => 'Facebook Only',
            'required'   => false,
            'value'      => 1
        ));

        // general app data group
        $this->addDisplayGroup(array('title', 'appid', 'appsecret', 'namespace', 'applink', 'fbonly'), 'general', array('legend' => 'General Optons'));

        // Facebook Only?
        $this->addElement('checkbox', 'fangate', array(
            'label'      => 'Fangate Page',
            'required'   => false,
            'value'      => 1
        ));

        // Facebook Only?
        $this->addElement('checkbox', 'welcome', array(
            'label'      => 'Welcome Page',
            'required'   => false,
            'value'      => 1
        ));

        // Facebook Only?
        $this->addElement('checkbox', 'help', array(
            'label'      => 'Help Page',
            'required'   => false,
            'value'      => 1
        ));

        // Facebook Only?
        $this->addElement('checkbox', 'entries', array(
            'label'      => 'Entries Page',
            'required'   => false,
            'value'      => 1
        ));

        // pages enabled group
        $this->addDisplayGroup(array('fangate', 'welcome', 'help', 'entries'), 'page', array('legend' => 'Page Optons'));

        // Add the title
        $this->addElement('text', 'ogtype', array(
            'label'      => 'Default Open Graph Type',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the title
        $this->addElement('text', 'ogtitle', array(
            'label'      => 'Default Open Graph Title',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the title
        $this->addElement('text', 'ogdesc', array(
            'label'      => 'Default Open Graph Description',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the title
        $this->addElement('file', 'ogimage', array(
            'label'      => 'Default App Image',
            'required'   => false
        ));

        // generic open graph data
        $this->addDisplayGroup(array('ogtype', 'ogtitle', 'ogdesc', 'ogimage'), 'og', array('legend' => 'Generic Open Graph data'));

        // Add the wall title
        $this->addElement('text', 'apptitle', array(
            'label'      => 'App Title',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the wall caption
        $this->addElement('text', 'appcaption', array(
            'label'      => 'App Caption',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 60))
                )
        ));

        // Add the wall message
        $this->addElement('text', 'appdesc', array(
            'label'      => 'App Description',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 255))
                )
        ));

        // app message details
        $this->addDisplayGroup(array('apptitle', 'appcaption', 'appdesc'), 'appdetails', array('legend' => 'App deatils (Used when sharing)'));

        // Add the wall title
        $this->addElement('text', 'wallmsg', array(
            'label'      => 'Wall Message',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 255))
                )
        ));

        // Add the wall title
        $this->addElement('text', 'friendmsg', array(
            'label'      => 'Friends Wall Message',
            'required'   => false,
            'validators' => array(
                    array('validator' => 'StringLength', 'options' => array(0, 255))
                )
        ));

        // app message details
        $this->addDisplayGroup(array('wallmsg', 'friendmsg'), 'wallmessages', array('legend' => 'Wall post messages'));

        // Add the submit button
        $this->addElement('submit', 'submit', array(
            'ignore'   => true,
            'label'    => 'Submit',
        ));

        // And finally add some CSRF protection
        $this->addElement('hash', 'csrf', array(
            'ignore' => true,
        ));

        // change markup of elements
        $this->setElementDecorators(array(
            'ViewHelper',
            array(
                'Description',
                array(
                    'tag'    => 'div',
                    'class'  => 'submit-button',
                    'escape' => false
                )
            ),
            array(
                array(
                    'data' => 'HtmlTag'
                ),
                array(
                    'tag'   => 'span',
                    'class' => 'element'
                )
            ),
            array(
                'Label',
                array(
                    'tag'    => 'label',
                    'class' => 'elementLabel',
                    'escape' => false
                )
            ),
            'File',
            array(
                array(
                    'data' => 'HtmlTag'
                ),
                array(
                    'tag'   => 'span',
                    'class' => 'element'
                )
            ),
            array(
                array(
                    'row' => 'HtmlTag'
                ),
                array(
                    'tag'   => 'li',
                    'class' => 'element-row'
                ),
            ),
            'Errors'
        ));

        // change markup of form
        $this->setDecorators(array(
            'FormElements',
            array(
                'HtmlTag',
                array(
                    'tag' => 'div',
                    'id'  => $this->_containerId
                )
            ),
            'Form',
            'Errors'
        ));

    }


}
  • 写回答

1条回答 默认 最新

  • dpswo40440 2012-09-04 14:46
    关注

    You have at least one "File" element in your form, you called setDecorators and did not include the "File" decorator, which is a required decoratotr for a 'File' element:

    35.6.4. Zend_Form_Element_File

    The File form element provides a mechanism for supplying file upload fields to your form. It utilizes Zend_File_Transfer internally to provide this functionality, and the FormFile view helper as also the File decorator to display the form element.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在