我想自定义zend表单的标记


I want to customise the markup of zend form

我有一个表单,我想为它定制标记。我使用类底部的装饰器。然而,我不断得到错误:

表单捕获到异常:找不到文件装饰器。

我想知道是否有人能给我举个例子。我基本上想把表单输出为,去掉标准布局。也许还可以添加一些自定义类。

更新

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

}

您至少有一个"文件"元素,则调用setDecorators,并且不包括"文件"装饰器,这是'File'元素所需的装饰器:

35.6.4.Zend_Form_Element_File

File表单元素提供了一种向表单提供文件上传字段的机制Zend_File_Transfer内部提供此功能FormFile视图帮助程序同时也是文件装饰器以显示窗体要素