Reputation: 18598
I'm attempting to create a custom form field in Zend_Form
to store a snippet of HTML that is required by SWFUpload(for the purposes of a flash file uploader).
I've tried following a few different tutorials but i'm getting pretty confused, so far this is what i have:
/application/forms/elements/SwfUpload.php
SwfUploadHelper.php
These files are autoloaded in Bootstrap (well, SwfUpload.php certainly is) .
SwfUpload.php:
class Custom_Form_Element_SwfUpload extends Zend_Form_Element
{
public $helper = 'swfUpload';
}
SwfUploadHelper.php:
class Custom_Form_Helper_SwfUpload extends Zend_View_Helper_FormElement
{
public function swfUpload()
{
$html = '<div id="swfupload-control">
<p>Upload upto 5 image files(jpg, png, gif), each having maximum size of 1MB(Use Ctrl/Shift to select multiple files)</p>
<input type="button" id="button" />
<p id="queuestatus" ></p>
<ol id="log"></ol>
</div>';
return $html;
}
}
when i instantiate this class like this:
class Form_ApplicationForm extends Zend_Form
{
public function init()
{
$custom = new Custom_Form_Element_SwfUpload('swfupload');
// etc etc
I get this error:
Message: Plugin by name 'SwfUpload' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/:/home/mysite/application/views/helpers/
Is it the case that it's expecting my helper to be in "home/mysite/application/views/helpers/
"? I've tried creating the same helper in there with the filename "SwfUpload.php" but the error remains. Not sure i this is purely a filename/path issue or something else.
thanks.
Upvotes: 1
Views: 7493
Reputation: 18598
This is what i ended up with, hope it helps someone else:
in /application/forms/elements/SwfUpload.php
class Custom_Form_Element_SwfUpload extends Zend_Form_Element
{
public $helper = 'swfUpload'; # maps to method name in SwfUpload helper
public function init()
{
$view = $this->getView();
$view->addHelperPath(APPLICATION_PATH.'/views/helpers/', 'Custom_Form_Helper');
}
}
in /application/views/helpers/SwfUpload.php
class Custom_Form_Helper_SwfUpload extends Zend_View_Helper_FormElement
{
public function init(){}
public function swfUpload()
{
$html = '<div id="swfupload-control">
<p>Upload upto 5 image files(jpg, png, gif), each having maximum size of 1MB(Use Ctrl/Shift to select multiple files)</p>
<input type="button" id="button" />
<p id="queuestatus" ></p>
<ol id="log"></ol>
</div>';
return $html;
}
}
Upvotes: 10
Reputation: 317177
API Docs for Zend_Form_Element
void __construct (string|array|Zend_Config $spec, [ $options = null])
* string|array|Zend_Config $spec
* $options
$spec may be:
* string: name of element
* array: options with which to configure element
* Zend_Config: Zend_Config with options for configuring element
* throws: Zend_Form_Exception if no element name after initialization
* access: public
See what it throws? Try
$custom = new Custom_Form_Element_SwfUpload('upload');
Upvotes: 3