Zend_Form 文件字段分隔符
我在按照我想要的方式塑造表单布局时遇到一些麻烦。这里的问题不是装饰文件元素本身,问题来自于函数:$file->setMultiFile(3)
。我似乎无法在多个文件输入元素之间放置分隔符,导致它们被放置在彼此后面的一行中。
这就是我创建文件元素的方式:
$oElement = new Zend_Form_Element_File('file');
$oElement->setLabel('File')
->setMultiFile(3)
->setDestination('location on server');
$this->addElement($oElement);
然后添加装饰器:
$this->getElement('file')->setDecorators(array(
'File',
'Errors',
array(array('td' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
array(array('tr' => 'HtmlTag'), array('tag' => 'tr'))
));
当前输出是:
<tr>
<td id="file-label">
<label class="optional" for="file">File</label>
</td>
<td>
<input type="file" id="file-0" name="file[]">
<input type="file" id="file-1" name="file[]">
<input type="file" id="file-2" name="file[]">
</td>
</tr>
我想要的是在输入元素之间有一个
,这样它们就不会放置在单行上。这可以通过装饰器实现吗?对于 radio/mutliselect/multicheckbox,有一个 setSeparator 函数可以做到这一点,但文件元素的情况似乎并非如此。
有人可以帮我吗? 提前致谢,
伊利安
I'm having some trouble shaping the form layout the way I want it to look. The problem here isn't decorating the file element itself, the trouble comes with the function: $file->setMultiFile(3)
. I can't seem to put a separator between multiple file input elements causing them to be placed in a row behind eachother.
This is how I create the file Element:
$oElement = new Zend_Form_Element_File('file');
$oElement->setLabel('File')
->setMultiFile(3)
->setDestination('location on server');
$this->addElement($oElement);
Then later I add the decorators:
$this->getElement('file')->setDecorators(array(
'File',
'Errors',
array(array('td' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
array(array('tr' => 'HtmlTag'), array('tag' => 'tr'))
));
The current output is:
<tr>
<td id="file-label">
<label class="optional" for="file">File</label>
</td>
<td>
<input type="file" id="file-0" name="file[]">
<input type="file" id="file-1" name="file[]">
<input type="file" id="file-2" name="file[]">
</td>
</tr>
What I want is to have a <br />
between the input elements so they're not placed on a single row. Is this possible through decorators? With the radio/mutliselect/multicheckbox there's a setSeparator
function that'll do this, but this doesn't seem to be the case for the file element.
Could anybody help me out here?
Thanks in advance,
Ilian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能有点作弊,但以下内容应该对您有用:
您可以在将元素附加到表单并更改装饰器之后放置该代码。
Zend_Form_Decorator_File
的 render() 方法在创建标记时使用分隔符,但它们无法让您设置它。放置和分隔符的设置已列入黑名单,但使用上述技巧,您仍然可以设置它们。在 Zend_Form_Decorator_File render() 中:
我必须将放置设置为 PREPEND,否则它会执行
使用 APPEND 时。*file input*
>*file input*
>*file input *
希望有帮助。
This may be cheating a bit, but the following should work for you:
You can place that code after you append the element to the form and change the decorators.
Zend_Form_Decorator_File
's render() method uses the separator when creating the markup, but they give you no way to set it. Setting of placement and separator are blacklisted, but using the above trick, you can set them anyway.In Zend_Form_Decorator_File render():
I had to set the placement to PREPEND, otherwise it did
<br />*file input*<br />*file input*<br />*file input*
when using APPEND.Hope that helps.