Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Form label decorator

I have a problem with label decorator. When I generate a form I have something like this:

<label id="user_email-label"><label for="user_email" class="required">e-mail</label>
</label>
<input type="text" name="user_email" id="user_email" value="" class="span4">

but I need :

<label for="user_email" class="required">e-mail</label>
<input type="text" name="user_email" id="user_email" value="" class="span4">

My code:

$oText = new Zend_Form_Element_Text('user_email');
$oText->clearDecorators();
$oText->setLabel($oTranslate->translate('e-mail'));
$oText->setAttrib('class','span4');
$oText->setRequired(true);
$oText->addValidator('NotEmpty', true);
$oText->addValidator('StringLength', true, array('max' => 200));
$oText->addValidator('EmailAddress', true);
$oText->addDecorator('ViewHelper');
$oText->addDecorator('Errors');
$oText->addDecorator('Label',array('tag'=>'label', 'placement' => 'prepend'));
$oText->setFilters(array('StringToLower','StringTrim'));
$this->addElement($oText);

And my second question is how can I put a checkbox inside label? When I am doing something like this:

 $oCheckbox = new Zend_Form_Element_Checkbox('remember_me');
    $oCheckbox->setLabel($oTranslate->translate('remember me'));
    $oCheckbox->setChecked(true);
    $oCheckbox->addDecorator('HtmlTag',array('tag'=>'label','class'=>'checkbox muted'));
    $oCheckbox->removeDecorator('DtDdWrapper');
    $oCheckbox->addDecorator('Label',array('tag'=>'label'));
    $this->addElement($oCheckbox);

I have:

<label class="checkbox muted">
<input type="hidden" name="remember_me" value="0"><input type="checkbox" name="remember_me" id="remember_me" value="1" checked="checked"></label>
<label id="remember_me-label"><label for="remember_me" class="optional">remember me</label></label>

but I need:

<label class="checkbox muted">
<input type="hidden" name="remember_me" value="0"><input type="checkbox" name="remember_me" id="remember_me" value="1" checked="checked">
remember me</label>

Any ideas?

Regards

like image 784
Michał Kalkowski Avatar asked Feb 19 '23 00:02

Michał Kalkowski


1 Answers

The part where you build your element, the 'tag' option

$oText->addDecorator('Label',array('tag'=>'label', 'placement' => 'prepend'));`

is not needed. Change it to:

$oText->addDecorator('Label',array('placement' => 'prepend'));

As for the second question, I think you would have to write your custom element to achieve that. Alternatively, you can use the view script to render each part of the element as you like.

like image 98
burntblark Avatar answered Feb 27 '23 13:02

burntblark