我有一个表单,我想为它自定义标记。我正在使用课程底部的装饰器。但是,我一直收到错误:
表单捕获的异常:找不到文件装饰器。
我想知道是否有人能够给我一个例子。我基本上想要输出表格并取消标准布局。也许还要添加一些自定义类。
更新
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'
));
}
}
答案 0 :(得分:2)
您的表单中至少有一个“文件”元素,您调用setDecorators
并且未包含“文件”装饰器,这是一个必需 decoratotr用于'文件'元素:
<强> 35.6.4。 Zend_Form_Element_File 强>
“文件”表单元素提供了一种向表单提供文件上载字段的机制。它利用 Zend_File_Transfer内部提供此功能,以及 FormFile视图助手以及文件装饰器来显示表单 元件。