-- fozzyuw <[EMAIL PROTECTED]> wrote
(on Tuesday, 09 September 2008, 03:13 PM -0700):
> My simple need now is to just simply add "<span>*
> Required</span>" into this XHTML code between the closing "</dl>" and
> the closing "</fieldset>" like this...
>
> - - - - - - - - - - - - - - - - - - - - - - - - -
> </dl>
> <span>* Required</span>
> </fieldset>
> - - - - - - - - - - - - - - - - - - - - - - - - -
>
> The "span" could be a "div" too, it doesn't really matter what HTML element
> it is. Likewise, "* Required" text could be changed at any time,
> dynamically.
I did something like this recently by creating a custom decorator that
created the small bit of markup I needed and attaching it to the form:
My_Form_Decorator_RequiredNotice extends Zend_Form_Decorator_Abstract
{
public function render($content)
{
return $content
. '<span>* Required</span>';
}
}
$form->addPrefixPath('My_Form_Decorator', 'My/Form/Decorator/',
'decorator');
$form->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'dl')),
'RequiredNotice',
'Fieldset',
'Form',
));
> I can figure out how to slap the "<span></span>" tag in there
> using Decorators, but I can't seem to figure out how to put my own
> personnalized content between the "span" tag.
For this, I'd take the example above, but allow optionally specifying a
"content" option to the decorator:
public function render($content)
{
if (null === ($markup = $this->getOption('content'))) {
$markup = '* Required';
}
return $content . '<span>' . $markup . '</span>';
}
Then, when instantiating, you'd do this:'
$form->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'dl')),
array('RequiredNotice', array('content' => 'My custom notice!')),
'Fieldset',
'Form',
));
> I tried a "Label" decorator on the "Display Group" element but Label's are
> not implemented for that element. Does that mean I'll have to create my own
> Display Group class to extend this functionality? Or is there an easier way
> to just put my own HTML elements with my own message into a form?
Hopefully the above will help.
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/