Quantcast

Remove <dt> from default Zend Form decorators

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Remove <dt> from default Zend Form decorators

rhaag71
Hi,

I am attempting to get my forms to have no html tags, I have attempted in
several ways, some came from here... http://mwop.net/blog/215-Rendering-
Zend_Form-decorators-individually (O'Phinney's site),
from that site I attempted the 'foreach' loop in my view script like so...

foreach ($form->getElements() as $element) {
                           $element->getDecorator('label')->setTag(null);
                        }

resulting in a "Call to a member function setTag() on a non-object" error,
as the same happens if I do this...

        $this->removeDecorator('HtmlTag');
        foreach ($this->getElements() as $element) {
            $element->addDecorator('Label');
            $element->getDecorator('Label')->setTag(null);
            $element->removeDecorator('HtmlTag');
            $element->removeDecorator('DtDdWrapper');

        }

after all of my 'addElement' code in my form class (extends Zend_Form).

If I put the above code at the top of my init() function, it does nothing
at all...my labels still have the '<dt>' tags rendering like so...

 <dt id="date-label"><label for="date" class="optional">Date
(DD/MM/YYYY):</label></dt>

I am trying to have no tags at all so I can call each element individually
in my veiw script and manipulate the form to my requirements, plus adding
<hr /> tags, etc.

Is there still a bug with setTag() ? do I have to add a decorator first,
then remove it? I'm a bit baffled on this one...

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove <dt> from default Zend Form decorators

Clint Lenard
I haven't tried a foreach loop, but I have had success in removing the dt
tags from MOST of the form elements... well, everything other than Submit,
by using:

->removeDecorator('htmlTag');

or

->removeDecorator('DtDWrapper');

Of course, I simply use these on the form elements, like so:

        $pswd = new Zend_Form_Element_Password('pswd');
        $pswd->setAttrib('size', 35)
             ->removeDecorator('htmlTag');

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Login')
               ->removeDecorator('DtDWrapper');

Since you're using a foreach loop - have you tried getElement() instead of
getElements() ?

Just curious. I'm interested in seeing a solution for this, too.

On Thu, Jan 19, 2012 at 4:55 PM, Rob Haag <[hidden email]> wrote:

> Hi,
>
> I am attempting to get my forms to have no html tags, I have attempted in
> several ways, some came from here... http://mwop.net/blog/215-Rendering-
> Zend_Form-decorators-individually (O'Phinney's site),
> from that site I attempted the 'foreach' loop in my view script like so...
>
> foreach ($form->getElements() as $element) {
>                           $element->getDecorator('label')->setTag(null);
>                        }
>
> resulting in a "Call to a member function setTag() on a non-object" error,
> as the same happens if I do this...
>
>        $this->removeDecorator('HtmlTag');
>        foreach ($this->getElements() as $element) {
>            $element->addDecorator('Label');
>            $element->getDecorator('Label')->setTag(null);
>            $element->removeDecorator('HtmlTag');
>            $element->removeDecorator('DtDdWrapper');
>
>        }
>
> after all of my 'addElement' code in my form class (extends Zend_Form).
>
> If I put the above code at the top of my init() function, it does nothing
> at all...my labels still have the '<dt>' tags rendering like so...
>
>  <dt id="date-label"><label for="date" class="optional">Date
> (DD/MM/YYYY):</label></dt>
>
> I am trying to have no tags at all so I can call each element individually
> in my veiw script and manipulate the form to my requirements, plus adding
> <hr /> tags, etc.
>
> Is there still a bug with setTag() ? do I have to add a decorator first,
> then remove it? I'm a bit baffled on this one...
>
> Thanks
>



--
Thanks,

Clint Lenard

www.ClintLenard.com
www.Affiliit.com

*"Great minds discuss ideas*, *average minds discuss events*, *small minds
discuss people*." - Eleanor Roosevelt

*"**I've learned that mistakes can often be as good a teacher as success.*"
- Jack Welch
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove <dt> from default Zend Form decorators

rhaag71
So...this is weird,

I had removed the 'echo $form->elementName->renderLabel()' calls from my view script and was putting some regular 'ol html in place of the labels (for now), after reading your response I go back, un-comment the foreach loop at the top of my view script, add a new 'renderLabel()' (like above) to some elements and all of a sudden it works now.

I like things to work, but I hate it when things just start working...this tells me nothing about what was happening before.

If you would like to try it too, please post back with your results. I did nothing significant between posting here...

Thanks though, I would like to figure out what happened
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove <dt> from default Zend Form decorators

Razorblade
Hello,
I think should be a good idea read this article where form decorator are clearly explained.

Anyway, to render just the element without any other html tag, using only the "ViewHelper" decorator should be fine, eg.

$formElement->setDecorator(array('ViewHelper'));

If you want this kind of decorator for all your form element use $this->setElementDecorators(array('ViewHelper')); within your form class


Regards
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove <dt> from default Zend Form decorators

rhaag71
Thanks for the link, I think I will have to read that article. I have done all my forms, up 'til now, in a different way, basically just 'echo' the entire form in my view. I think I have this part working, but now my validation messages are not showing up. Those may be a part of the decorations (?). I must have something to do with it.

Time to revisit Zend forms :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Remove <dt> from default Zend Form decorators

Mike Wright
On 01/20/2012 12:55 PM, rhaag71 wrote:
> Thanks for the link, I think I will have to read that article. I have done
> all my forms, up 'til now, in a different way, basically just 'echo' the
> entire form in my view. I think I have this part working, but now my
> validation messages are not showing up. Those may be a part of the
> decorations (?). I must have something to do with it.
>
Hi rhaag71,

I've had my share of troubles with decorators but with help from this
list I now have some very nice looking forms.  At first I didn't
appreciate how much thought the zf krewe had put into them (apologies to
MWO'P).

I think Razorblade was on track.  There are an assortment of decorators
in addition to "ViewHelper", such as "Errors", "Tooltip", "Description",
"HtmlTag", "Form", "Fieldset", and many others.

How about:

$this->setElementDecorators(array('ViewHelper', 'Errors'));

May do the trick.

Hope that's the solution,
Mike Wright

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Loading...