SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast mithra62's Avatar
    Join Date
    Nov 2004
    Location
    Van Nuys
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to explicitly set a form layout using zend_form?

    I've been working with Zend Framework for a couple weeks so this might be a complete noobie question but I'm wondering if there's a way to customize the layout of forms in an explicit way using Zend_Form. I've looked all over the place but every example of Zen-Form I've found use the echo example.

    For example, when I work with Smarty and HTML_QuickForm I have the option of placing each form element onto the page where ever I want.
    PHP Code:
    {if $Form.errors}<span class="errorMessage">Error!</span>{/if}
    {if 
    $Form.Email.error}Fill out field{if}
    <
    div id="EmailField">{$Form.Email.html}</div>
    {
    $Form.Submit.html
    But with Zend Framework it looks like I have to decorate the form elements in the actual php code and echo the completed form:
    PHP Code:
    echo $this->form
    I don't like this because it requires modification of the php to change the form layout and complicated layouts would be a nightmare using decorators. (I have some clients who's designers have some pretty outlandish layouts for some forms.)

    If it's not possible are there any php frameworks that do allow this level of control? How does CakePHP or Symphony handle form layouts?

  2. #2
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do the HTML yourself and just have it generate the actual elements.

    PHP Code:
    <form id="<?= $this->form->getName() ?>" enctype="<?= $this->form->getEnctype() ?>" action="<?= $this->form->getAction() ?>" method="<?= $this->form->getMethod() ?>">
         Some HTML
        <?= $this->form->username ?>
         Some HTML
         <?= $this->form->password ?>
         Some HTML
    </form>
    Adrian Schneider - Web Developer

  3. #3
    SitePoint Enthusiast mithra62's Avatar
    Join Date
    Nov 2004
    Location
    Van Nuys
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! That's exactly what I was looking for

    Do you know how I would check for any error messages inside the view?

  4. #4
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try $this->form->getErrorMessages()
    Adrian Schneider - Web Developer


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •