Search code examples
phpcsszend-formzend-decorators

How can I set the class for a <dt> element in a Zend_Form?


I'm trying to set the width of the style for a group of < dt > elements in a Zend_Form. Is there a way to set a class for a dt element, so the end result would be something like this:

     <dt id="name-label" class="xyz" > // trying to add the 'class="xyz"
        <label class="required" for="name">Name:</label>
     </dt>

    <dd id="name-element">
        <input type="text" maxlength="255" size="30" value="" id="name" name="name">
    </dd>

Solution

  • I finally found the solution - i needed to wrap the dt,dd elements in a < dl > tag and set the class of the < dl > tag. then i set the css for the < dt > elements through the < dl > class, like so:

    Sample element:

            $question = new Zend_Form_Element_TextArea('question'.$i);
            $question->setLabel('Question '.$i.':')
                 ->setAttrib('rows', 10)->setAttrib('cols', 40)->setAttrib('class', 'richtexteditor')
                 ->addFilter('StringTrim')
                 ->addDecorator('HtmlTag', array('tag' =>  'dd','id'=> 'question'.$i.'-element',
                                                 'style'=>'width:350px;max-height:202px;'
                                                    )
                                     )
                 ->addDecorator(array('dlTag'=>'HtmlTag'), array('tag' =>  'dl','class'=> 'xyz')) //added this line
                 ->addDecorator('Errors', array('class'=>'custom-errors'))
                 ->setOptions(array('onkeyup'=>'textCounter();',
                                    'onkeydown'=>'textCounter();'
                                          )
                                    );
    

    Then, i added the following to my css file:

    dl.xyz{
            margin: 0;
    }
    .xyz dt {
        width:97px;
        padding-left: 0px;
        margin-left: -15px;
    
    }
    

    this achieves what i was aiming for all along - modifying certain dt elements' style while retaining a general/default < dt >style for the entire form.