+ Reply to Thread
Results 1 to 3 of 3

Thread: using Div with Zend Form

  1. #1
    raman is offline Junior Member
    Join Date
    Nov 2008
    Posts
    3

    Smile using Div with Zend Form

    Hi All,

    I am new to Zend Framework and trying to design UI using Zend_Forms. What I need to do is to switch between 2 divs using javascript. One div will have e.g First Name and Surname and other will have company name. I will switch between these divs depending on Individual and company selection. I tried to use used the following code:

    $first_name = new Zend_Form_Element_Text('first_name');
    $first_name
    ->setRequired(true)
    ->addValidator(new Zend_Validate_Alnum())
    ->addFilter('StringToLower')
    ->setLabel('First Name');

    $surname = new Zend_Form_Element_Text('surname');
    $surname
    ->setRequired(true)
    ->addValidator(new Zend_Validate_Alnum())
    ->addFilter('StringToLower')
    ->setLabel('Surname');

    $form->addElement( $first_name );
    $form->addElement( $surname );
    $form->addDisplayGroup(array('first_name','surname'), 'individual');

    $form->setDisplayGroupDecorators(
    array(
    'FormElements',
    array('HtmlTag', 'tag' => 'div')
    )
    );

    The problem I am having is that I get the div properly working but I don't get the id for the div. So I am not able to manipulate using javascript. Also I don't know how to hide or unhide the div using zend_form. Can somebody give me guidance on how to make div properly working using Zend_Forms?

  2. #2
    melatbabel is offline Junior Member
    Join Date
    Nov 2008
    Posts
    1

    Default

    Zend Form display groups and decorators with example Zend Framework Weblog appears to have the answer.

    Code:
    $form->addElement( $first_name );
    
    $form->addElement( $surname );
    
    $form->addDisplayGroup(array('first_name','surname'), 'individual'); 
    
    $form->setDecorators(array(
    'FormElements',
    array('HtmlTag',array('tag'=>'div','id'=>'blah')),
    'individual'
    ));

  3. #3
    raman is offline Junior Member
    Join Date
    Nov 2008
    Posts
    3

    Default

    Thanks melatbabel. You are great.

+ Reply to Thread

Similar Threads

  1. Dojo form in Zend Framework::Form does not get styled by CSS
    By xsiyez in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 05-06-2010, 03:00 PM
  2. Zend Form: how to declare start and end of form in view?
    By icegreenberry in forum Core Infrastructure
    Replies: 4
    Last Post: 11-23-2009, 12:31 PM
  3. Zend Form file upload not kept when form validation error
    By gentlemich in forum Core Infrastructure
    Replies: 1
    Last Post: 09-26-2009, 11:32 AM
  4. Zend Form Decorators and Form Labels
    By CreedFeed in forum General Q&A on Zend Framework
    Replies: 1
    Last Post: 06-24-2009, 10:46 PM
  5. Zend Form - Creating Form elements
    By dele454 in forum Core Infrastructure
    Replies: 13
    Last Post: 08-17-2008, 03:31 PM

Posting Permissions

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