Zend_Form 文件字段分隔符

发布于 2024-12-17 11:39:20 字数 1242 浏览 4 评论 0原文

我在按照我想要的方式塑造表单布局时遇到一些麻烦。这里的问题不是装饰文件元素本身,问题来自于函数:$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海风掠过北极光 2024-12-24 11:39:20

这可能有点作弊,但以下内容应该对您有用:

$fd = $oElement->getDecorator('File');

$fd->setOption('placement', 'PREPEND')
   ->setOption('separator', '<br />');

您可以在将元素附加到表单并更改装饰器之后放置该代码。

Zend_Form_Decorator_File 的 render() 方法在创建标记时使用分隔符,但它们无法让您设置它。放置和分隔符的设置已列入黑名单,但使用上述技巧,您仍然可以设置它们。

在 Zend_Form_Decorator_File render() 中:

$separator = $this->getSeparator();
$placement = $this->getPlacement();
//...

// in a loop, create the array of input elements
$markup[] = $view->formFile($name, $htmlAttribs);

//...
// join each file element by separator, which cannot be set with setSeparator()
$markup = implode($separator, $markup);

我必须将放置设置为 PREPEND,否则它会执行
*file input*
>*file input*
>*file input *
使用 APPEND 时。

希望有帮助。

This may be cheating a bit, but the following should work for you:

$fd = $oElement->getDecorator('File');

$fd->setOption('placement', 'PREPEND')
   ->setOption('separator', '<br />');

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():

$separator = $this->getSeparator();
$placement = $this->getPlacement();
//...

// in a loop, create the array of input elements
$markup[] = $view->formFile($name, $htmlAttribs);

//...
// join each file element by separator, which cannot be set with setSeparator()
$markup = implode($separator, $markup);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文