Question

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

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top