1

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.

2
  • Here is a question like yours: stackoverflow.com/questions/2056737/… Commented Jan 13, 2010 at 15:26
  • thats actually my question too, not intending to spam but its difficult on stackoverflow when the question kind of changes tact like this one has. that was more a case of whats the theory, this is more a case of troubleshooting specifics. Commented Jan 13, 2010 at 15:29

2 Answers 2

10

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

3

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');

1 Comment

just noticed that myself, d'oh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.