• How long till you will be a ZCE on Zend Framework? 😀

  • Well, 3-4 months max…

  • Why not change the display to inline for all DDs? Some XHTML rule?

  • Because it would generate a very long possibly unbroken line of labels and form items. Just imagine how a form where all the elements have display:inline would look like…

  • Yummy! realmendontneednospacebars

  • Yeap! Real men don’t use backups either…

  • True men don’t kill coyotes!

  • Great quality post! Thanks!

  • seddass

    Very interesting article.
    Is there a way to set “hidden” class to dt element instead of setting label class “hidden”. I mean that DT is still visible and creates unnecessary space in the design.

    See the code that is generated with yours helper:
     

  • Add

    to your CSS file…

  • Jack Tanner

    One alternative is this:

    Note that you can’t stack those two, because they return a boolean, not the object itself.

  • Jack Tanner> if you do that, your html won’t validate. It will look something like this:

    I care about standards 😛

  • Jack Tanner

    Tudor: yes, you’re right, that would produce invalid HTML. But it’s also possible to remove the dl/dt/dd nonsense from the form and non-hidden form elements, leaving clean, simple, and valid HTML.

  • Yes, this hard to remove extra markup in the wrong places and inability to place good markup where you want when you want is making me batty.

    The rest works fine but the decorators seem kludgy to me.

    And I’d love if the docs that showed examples made sure to include the config file w/ each one. By sticking this stuff in a config file, you can reuse validators/filters in your javascript.

  • Colin

    Try changing the default element decorators. There is a good post about this on the dev zone, http://devzone.zend.com/article/3450.

  • Colin> it will generate invalid HTML code…

  • Jack Tanner

    By the way, I recently came across this bug in ZF where it generates invalid form labels (in its default config).

    http://framework.zend.com/issues/browse/ZF-6426

  • (Apparently it replaced & n b s p ; with space in my above reply.)

  • Zend escapes the label, so it outputs ” ” in the actual HTML. Rather than toying with the escape function, I just used the following workaround:

    (Assuming that $decorators is the result of $element->getDecorators()).

  • Andy

    This is much easier to really hide the hidden field: Simply delete the Decorators of the element:

    $hiddenElement->setDecorators(array());

  • That will generate invalid xhtml…see few comments above! I want my pages to validate…

  • Slam

    Fixing this problem with a View Helper is a waste of time imho.

    I created a mother class (that extends Zend_From) for all my forms, and rewritten render() function:

    So no different code is written in forms or views.
    You can use even Tudor solution with my implementation.

    P.S.: Tudor, make possible and easily visibile for all how to <code> comment code plz.

  • Slam> You just add <pre lang=”php”>code</pre>. I’ve edited you comment and added the proper highlighting. The whole idea is keeping the outputted html clean and standards compliant.

    And, as always, there are more than one ways to get things done and people adhere to different philosophies. I’ve used the view helper approach because this is a presentation issue (how the form will be displayed) and presentation logic should stay at the “view level” of the MVC paradigm.

  • Slam

    Forms are not properly in one letter of the MVC acronym, forms are forms, in fact in a form you manage the Model/Control of a form (validators, ‘required’ etc) and also the View (decorators, label, etc), so i think that is right and legitimate to manipulate all form properties directly in form classes.

    Moreover, that implementation skimp lines of code and new classes creation with the same results and no different business logic nor logic error.

    Btw, this is my interpretation.

  • The way that the form’s widgets are rendered – with an extra CSS class in my case – is a presentation issue, that’s why I went for the view helper approach.

    But, of course, one can take the best of both worlds and do it like:

    This will yield valid XHTML code and reside in the parent form. It’s not a matter of right or wrong, but rather of personal opinions on design patterns.

  • Exception e

    @Tudor Your last solution will still generate dt’s without a class. At best it will add a class to the inside the .

    Could you confirm this, or did you prepare your elements in a special way (changing the decorators etc).

  • Exception e
  • Iacovos Constantinou

    You should use ViewHelper and HtmlTag decorators in order to achieve this. The following piece of code will completely ignore the label tag (incl. the dl) and it will generate both the dd and input tags.

  • Exception e

    @Iacovos Constantinou Thank you!

  • LC

    I use …

    … stacked and it works, for hidden and hash elements.

    I don’t care if it does not validate.

  • Croma

    Really helpful info.

    I too like to get my pages validated.

    Thanks

  • I found another way to change the html tag into one with a class=”hidden”. In your method you loop through all elements, which can cost a lot when you use large forms. Also with subforms the method doesn’t really work well.

    I override the loadDefaultDecorators for the Zend_Form_Element_Hidden which gives the opportunity to add the class directly when the hidden elements are added (and not only when rendered).

    Because it’s too long to post the whole story, here’s just the link to my blog post:
    http://juriansluiman.nl/en/blog/article/106/hide-hidden-zend_form-elements

  • Thank you!
    Very helpful!

  • Fantastic job dude. Cool.

  • Adolfo

    nice one, thanks!

  • Atef

    i force the hidden value of the checked input to 1 :

Advertisment ad adsense adlogger