views:

80

answers:

1
<div class="field50Pct">
 <div class="fieldItemLabel">
  <label for='First Name'>First Name:</label>
 </div>
 <div class="fieldItemValue">
  <input type="text" id="firstname" name="firstname" value="" />
 </div>
</div>

<div class="clear"></div>

I want the code to appear like this in source code . how do i write the same thing in zend using decorators ?

The element is like

  $firstname = new Zend_Form_Element_Text('FirstName');
        $firstname->setLabel('FirstName')
                 ->setRequired(true)
                 ->addFilter('StripTags')
                 ->addFilter('StringTrim')
                 ->addErrorMessage('Error in First Name')
                 ->addValidator('NotEmpty');
+4  A: 

This seems to work for me: (with <div class="clear"></div> after the input)

$firstname->setDecorators(array(
        'ViewHelper',
        'Description',
        'Errors',
        array('HtmlTag', array('tag' => 'div', 'class' => 'fieldItemValue')),
        array(array('labelDivOpen' => 'HtmlTag'), 
              array('tag' => 'div', 
                    'placement' => 'prepend', 
                    'closeOnly' => true)),
        'Label',
        array(array('labelDivClose' => 'HtmlTag'), 
              array('tag' => 'div', 
                    'class' => 'fieldItemLabel', 
                    'placement' => 'prepend', 
                    'openOnly' => true)),
        array(array('fieldDiv' => 'HtmlTag'), 
              array('tag' => 'div', 'class' => 'field50Pct')),
        array(array('divClear' => 'HtmlTag') , 
              array('tag' => 'div' ,
                    'class' => 'clear',
                    'placement' => 'append'))
    ));
Keyne
i ma new to zend ..can u just explain me the code you have written. so that i can try to write on my own next time!
pradeep
how do i write <div class="clear"></div> after some elements??
pradeep
Basically, I'm seting decorators to the firstname field.http://devzone.zend.com/article/3450http://codeutopia.net/blog/2008/08/07/zend_form-decorator-tips/
Keyne
how do i write <div class="clear"></div> after some elements??
pradeep
I've edited and added this example...
Keyne
i got ur code!1st one i am working on. what are the ones written 'ViewHelper','Description','Helpers' wht do they represent. and in the further code how does it recognise the class is for label / text box or whole field!!??
pradeep
cant i add the class clear in the 1st example only bcos i have started to work on 1st example!
pradeep
nope the earlier thing worked..but the clear thing did not work!
pradeep
its coming like <div class="field50Pct"><div class="fieldItemLabel"><label for="LastName" class="required">LastName</label></div><div class="fieldItemValue"><input type="text" name="LastName" id="LastName" value="" /></div><div class="clear"></div></div>but the </div><div class="clear"></div> must come after last div ends i.e of the <div class="field50Pct"> ends
pradeep
i placed the array( array('divClear' => 'HtmlTag') , array('tag' => 'div' , 'class' => 'clear', 'placement' => Zend_Form_Decorator_Abstract::APPEND) ),after the field50Pct class .so it worked thanks a lot ..if u can help me with this question i will be greatful what are the ones written 'ViewHelper','Description','Helpers' wht do they represent. and in the further code how does it recognise the class is for label / text box or whole field!!??
pradeep
ViewHelper represent the field itself, the description you can remove, since you're not using it (http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.description). And about the HtmlTag that decorate the label, is due the parameters "openOnly" and "closeOnly", also due to the order that decorators are rendered. Please, take a look at the links I sent you.
Keyne
for fieldset its coming in manner like <dt id="GeneralInformation-label"> </dt><dd id="GeneralInformation-element"><fieldset id="fieldset-GeneralInformation"><legend>General Information</legend><dl>i just need it in the ways like <fieldset id="personnel"><legend>Personal Data</legend>how do do it?
pradeep
I'm not sure if I understand you. Do you want print just the fieldset without dt tag?
Keyne
yes thats my requirement
pradeep