This is great, thanks for your help.
I am still getting into grips with zend form and zend dojo.
Basically I wanted to be able to inject custom html code in various parts of
the form, which works great now. I'm including the code below, in case it is
useful to anyone else.
In my form:
$myHtml = '<h1>Test Custom Html</h1>';
require_once 'MyProject/Form/Element/CustomHtml.php';
$custom = new CustomHtml('custom');
$custom->setValue($myHtml);
$custom->addDecorators(array(
'ViewHelper',
array('HtmlTag', array('tag' => 'li'))
));
// inject it wherever you want
$this->addElement($custom);
and.... add the helper class (thanks PHPScriptor)
class MyProject_View_Helper_CustomHtml extends Zend_View_Helper_FormElement
{
protected $_customHtml;
public function customHtml($name, $value = null, $attribs = null)
{
return $value;
}
}
PHPScriptor wrote:
>
> I'm not sure what you want to do. But if you define public $helper =
> 'formNote' you should make something like:
>
> class Zend_View_Helper_FormNote extends Zend_View_Helper_FormElement {
> public function formNote($name, $value = null, $attribs = null)
> {
> ... bla bla bla
> return ...
> }
> }
>
> let us know if this helped you on the way
>
>
> antonis wrote:
>>
>> Hello,
>>
>> I came accross to a post with the following code:
>>
>> require_once 'Zend/Form/Element/Xhtml.php';
>>
>> class My_Form_Element_Note extends Zend_Form_Element_Xhtml
>> {
>> /**
>> * Default form view helper to use for rendering
>> * @var string
>> */
>> public $helper = 'formNote';
>> }
>>
>> (I don't know if formNote is meant to be used for that, but you can use
>> your own view helper)
>>
>> Then you add the element like that:
>> $note = new My_Form_Element_Note('note');
>> $note->setValue('<p>Some notes...</p>');
>> $note->addDecorators(array(
>> 'ViewHelper',
>> array('HtmlTag', array('tag' => 'li')) // which ever element you use
>> to wrap your elements in the form
>> ));
>>
>> However, I don't understand how to create the view helper.
>>
>> I've got started with
>>
>> class Project_View_Helper_CustomHtml
>>
>> but, where do I extend it and how do I capture the data?
>>
>> Any ideas much appreciated.
>>
>> Thanks,
>>
>> Antonis
>>
>
>
--
View this message in context:
http://www.nabble.com/Adding-custom-HTML-to-form-through-View-Helper-tp22245561p22268390.html
Sent from the Zend Framework mailing list archive at Nabble.com.