How can I customize the appearance of forms generated by Zend_Form?
You're probably looking for decorators. All forms and form elements in Zend_Form use decorators to render their output.
How can I add extra HTML (such as a link) to my form element?
This can easily be done using decorators. For instance using the Description decorator. It is important to note though that you will need to turn off escaping for the output of the decorator:
Now, you can use the following to add extra HTML to the element:
Why can't Zend_Form render my File element without errors?
The file element needs a special file decorator, which is added by default. When you set your own decorators for file elements, you delete the default decorators. For example:
You should use a File decorator instead of the ViewHelper for the file element, like so:
How can I detect if an optional file has been uploaded?
The receive() method will return true for file elements that are not required. The reason is that you said "the file can be omitted, and that's ok for me". The receive() method will return false only in the event of a failure.
Still there are several ways to detect if a file has been uploaded or not:
Use isUploaded which returns a boolean
Use getFileName which returns null in this case (note that you must use the latest release for this behaviour)
Use getFileInfo which will have an empty 'file' key and the flag 'isUploaded' set to false
3 Comments
comments.show.hideOct 27, 2009
Anonymous
with regards to using 'File' and viewscript; how do you use them together?
doing this:
$file->setDecorators(array(
array(
'ViewScript',
array(
'viewScript' => 'input.phtml',
'class' => 'form element'
)
),
array('File'),
))
results in 2 file upload boxes?
Jul 26, 2010
Anonymous
at point 2: "How can I add extra HTML (such as a link) to my form element?"
it should read
$element->setDecorators(array(
...
array('Description', array('escape' => false)),
...
));
instead of
$element->setDecorators(array(
...
array('Description', array('escape', false)),
...
));
May 24, 2011
Anonymous
with regards to using 'File' and viewscript; Medion Akku how do you use them together?