Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]]></ac:plain-text-body></ac:macro>

<p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]]></ac:plain-text-body></ac:macro> <strong>How can I customize the appearance of forms generated by <code>Zend_Form</code>?</strong></p>
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]></ac:plain-text-body></ac:macro>
<p>You're probably looking for <a href="http://devzone.zend.com/article/3450-Decorators-with-Zend_Form">decorators</a>. All forms and form elements in Zend_Form use decorators to render their output.</p>
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]
]></ac:plain-text-body></ac:macro>

<p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]]></ac:plain-text-body></ac:macro> <strong>How can I add extra HTML (such as a link) to my form element?</strong></p>
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]></ac:plain-text-body></ac:macro>
<p>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:</p>
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
$element->setDecorators(array(
array('ViewHelper'),
array('Description', array('escape', false)),
array('Errors'),
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt')),
));
]]></ac:plain-text-body></ac:macro>
<p>Now, you can use the following to add extra HTML to the element:</p>
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
$element->setDescription('<strong>This contains HTML that will actually be parsed by the browser, not escaped</strong>');
]]></ac:plain-text-body></ac:macro>
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]
]></ac:plain-text-body></ac:macro>

<p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]]></ac:plain-text-body></ac:macro> <strong>Why can't <code>Zend_Form</code> render my <code>File</code> element without errors?</strong></p>
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]></ac:plain-text-body></ac:macro>
<p>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:</p>
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
$element->setDecorators(array(
array('ViewHelper'),
array('Errors')
));
]]></ac:plain-text-body></ac:macro>
<p>You should use a <code>File</code> decorator instead of the <code>ViewHelper</code> for the file element, like so:</p>
<ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
$element->setDecorators(array(
array('File'),
array('Errors')
));
]]></ac:plain-text-body></ac:macro>
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]
]></ac:plain-text-body></ac:macro>

<p><ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]]></ac:plain-text-body></ac:macro> <strong>How can I detect if an optional file has been uploaded?</strong></p>
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]></ac:plain-text-body></ac:macro>
<p>The <code>receive()</code> method will return <code>true</code> 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 <code>receive()</code> method will return false only in the event of a failure.</p>

<p>Still there are several ways to detect if a file has been uploaded or not:</p>

<ul>
<li>Use isUploaded which returns a boolean</li>
<li>Use getFileName which returns null in this case (note that you must use the latest release for this behaviour)</li>
<li>Use getFileInfo which will have an empty 'file' key and the flag 'isUploaded' set to false
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[]]></ac:plain-text-body></ac:macro></li>
</ul>

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 27, 2009

    Anonymous

    <p>with regards to using 'File' and viewscript; how do you use them together?</p>

    <p>doing this:</p>

    <p>$file->setDecorators(array( <br />
    array(<br />
    'ViewScript', <br />
    array(<br />
    'viewScript' => 'input.phtml',<br />
    'class' => 'form element'<br />
    )<br />
    ),<br />
    array('File'), <br />
    ))</p>

    <p>results in 2 file upload boxes?</p>

  2. Jul 26, 2010

    Anonymous

    <p>at point 2: "How can I add extra HTML (such as a link) to my form element?"</p>

    <p>it should read</p>

    <p>$element->setDecorators(array( <br />
    ...<br />
    array('Description', array('escape' => false)),<br />
    ...<br />
    )); </p>

    <p>instead of</p>

    <p>$element->setDecorators(array( <br />
    ...<br />
    array('Description', array('escape', false)),<br />
    ...<br />
    )); </p>

  3. May 24, 2011

    Anonymous

    <p>with regards to using 'File' and viewscript; <a href="http://www.medionakku.de/">Medion Akku</a> how do you use them together?</p>