我对标签装饰器有疑问。当我生成一个表单时,我有这样的东西:
<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">
但是我需要 :
<label for="user_email" class="required">e-mail</label>
<input type="text" name="user_email" id="user_email" value="" class="span4">
我的代码:
$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);
我的第二个问题是如何在标签内放置一个复选框?当我做这样的事情时:
$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);
我有:
<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>
但是我需要:
<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>
有任何想法吗?
问候