0
votes

I am trying to make a stand alone Zend Form with a custom form element. I need use custom view helper to create this element. How do I register a custom view helper path without an application.ini file?

set_include_path(
implode(PATH_SEPARATOR, array(
    get_include_path(),
    PATH_TO_ZF_LIBRARY
)));

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();

$autoloader->registerNamespace( 'My' ); 

$form = new Zend_Form;

... create and add zend form elements here

//display form
echo $form->render(new Zend_View());

Also, will the custom Zend_Form_Element know to look for the custom helper in the new path? According to the docs all I have to do is create public $helper var with the class name of the view helper. But I can't figure out if that will work with a custom view helper.

class My_Form_Element_Ssn extends Zend_Form_Element_Xhtml 
{
    public $helper = 'ssnElement';

    public function setValue()
    {

    }

    public function getValue()
    {
        return '12345';
    }
}

class My_View_Helper_SsnElement
extends Zend_View_Helper_FormElement
{

    public function ssnElement( $name, $value = null, $attribs = null )
    {
        return 'SSN';
    }
}

I thank you in advance for your assistance.

1

1 Answers

0
votes

Try:

$view = new Zend_View();
$view->addHelperPath('/path/to/My/View/Helper', 'My_View_Helper');

echo $form->render($view);