【问题标题】:Zend Checkbox Decorator IssueZend 复选框装饰器问题
【发布时间】:2011-06-20 10:34:43
【问题描述】:

你好,我正在尝试做一个复选框显示:

<input name="choice2" id="choice2" value="1" type="checkbox">
<label for="choice2" class="optional">Credit Card</label><br />
Some text

<input name="choice2" id="choice2" value="1" type="checkbox">
<label for="choice2" class="optional">Credit Card</label><br />
Some text

我非常接近以下代码:

$lbl_spagym = 'Credit Card<br />
              <p class="description">Some text</p><br />';

$chk_spagym = new Zend_Form_Element_Checkbox('chk_spagym');
$chk_spagym->setLabel($lbl_spagym)
           ->setDecorators(array(
           'ViewHelper',
        'Description',
            'Errors',
        array('Label', array('placement' => 'APPEND', 'escape' => false)),
        array('HtmlTag', array('tag' => 'div'))
    )); 

它呈现为:

<div>
<input type="hidden" name="chk_bank" value="0" />
<input type="checkbox" name="chk_bank" id="chk_bank" value="1" checked="checked" />
<label for="chk_bank" class="optional">Credit Card<br />
                     <p class="relocation_descr">Some text</p><br />
</label></div>

但我需要将&lt;p&gt;&lt;/p&gt; 排除在标签标签之外,因为“某些文本”是描述而不是标签。我玩了几天的装饰器,但无法正确处理这种行为。在此感谢任何 cmets。

【问题讨论】:

    标签: zend-framework checkbox zend-form


    【解决方案1】:

    您应该能够使用类似的东西创建该标记

    $form->addElement('checkbox', 'choice2', array(
        'label'      => 'Credit Card',
        'decorators' => array(
            'ViewHelper',
            array('Label', array('placement' => 'append',
                                 'class'     => 'optional'))
        )
    ));
    

    这将为复选框“关闭”值生成一个隐藏元素,但相信我,你想保留它。

    【讨论】:

    • thans 但这并不是我真正需要的。我刚刚改述了我的问题。
    【解决方案2】:

    我的问题是:

    $checkbox_e->setLabel($e_label)
               ->setDecorators(array('ViewHelper',
                                     'Description',
                                     'Errors',
                                     array('Label',
                                           array('placement'=>'APPEND')),
                                           array('HtmlTag', array('tag' => 'div'))));
    

    【讨论】:

    • StackOverflow 不是一个 论坛 它是一个 Q.A.地点。如果您有其他信息要添加到原始问题中,请编辑您的原始帖子。
    猜你喜欢
    • 2011-07-09
    • 2010-11-12
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-07-13
    相关资源
    最近更新 更多