Thanks in advance for any thoughts on the following:
1) Can anyone suggest the best way to implement the following in a
form: a Zend_Form_Element_File if no image has been uploaded. But if
an image has been uploaded, the image appears with a "delete" button.
Would a custom form element be best or would you just hide/show the
various elements with Javascript? Or is it already built-in!?
2) And as a second question: I can't find any way to do this. Is there
any way to just insert a random blob or row of HTML in your form like:
<dl>
<dt>Label</dt><dd><input type...></dd>
<dt>Label</dt><dd><input type...></dd>
<dt>Label</dt><dd><input type...></dd>
<p>Hi look at me!</p>
<dt>Label</dt><dd><input type...></dd>
<dt>Label</dt><dd><input type...></dd>
</dl>
Is there any way to insert the line "Hi look at me!" without
decorating the element above it or below it and without creating a
custom class?
3) Is there a problem with the current version of the
Zend_Form_Element_File? The element doesn't appear to print with the
row decorator.
<?php
class forms_AdminArticleForm extends Zend_Dojo_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('article_form')
->setAction(URL.'/admin/article/save')
->setMethod('post')
->setAttrib('enctype', 'multipart/form-data')
->setAttrib('id', 'article-form');
$title = new Zend_Form_Element_Text('title');
$title->setLabel('Title')
->setRequired(true)
->addValidator('NotEmpty')
->setAttribs(array('size'=>'40'))
->addValidator('StringLength', false, array(1, 128));
$author = new Zend_Form_Element_Text('author');
$author->setLabel('Author')
->setRequired(true)
->setAttribs(array('size'=>'40'))
->addValidator('NotEmpty')
->addValidator('StringLength', false, array(1, 64));
$image = new Zend_Form_Element_File('image_name');
$image->setLabel('Upload an image:')
->setDestination(AP . '/application/tmp/upload-staging')
->addValidator('Size', '500kb');
$submit = new Zend_Form_Element_Submit('action');
$submit->setLabel('Save');
$this->addElements(array(
$title, $author, $image, $submit
));
}
}
This class generates the following HTML code:
<form id="article-form" action="/admin/article/edit" method="post"
enctype="multipart/form-data">
<dl class="zend_form">
<dt><label for="title" class="required">Title</label></dt>
<dd><input type="text" name="title" id="title" value="Here ya go"
size="40"></dd>
<dt><label for="author" class="required">Author</label></dt>
<dd><input type="text" name="author" id="author" value="dudeness"
size="40"></dd>
<input type="file" name="image_name" id="image_name" helper="formFile">
<dt> </dt>
<dd><input type="submit" name="action" id="action" value="Save"></dd>
<dt> </dt>
<dd><input type="hidden" name="article_id" value="4" id="article_id"></
dd>
</dl>
</form>