2013-01-31 29 views
0

我正在添加一个同意复选框到现有的表单。我无法将标签呈现在复选框的右侧。我究竟做错了什么?如何在元素的右侧渲染标签?

请注意,复选框使用$this->addElement(创建,因为表单的其余部分是以这种方式创建的。

我感谢你在前进。

$this->addElement('checkbox', 'isUserConsent', array(
     'options' => array(array('placement' => 'APPEND')), 
     'label' => 'Plz activate', 
     'validators' => array(
      array('InArray', false, array(
       'hay' => array(1), 
       'messages' => 'Please check the consent box'), 
      ) 
     ), 
     'decorators' => array('ViewHelper','Errors','Label'), 
)); 

回答

2

默认为预先设置的标签,但你可以通过修改装饰的“位置”选项来改变这一点:

$this->getElement('isUserConsent')->getDecorator('label')->setOption('placement', 'append'); 

编辑:我从来不使用这个语法来装饰,但它应该是这样的:

$this->addElement('checkbox', 'isUserConsent', array(
     'options' => array(array('placement' => 'APPEND')), 
     'label' => 'Plz activate', 
     'validators' => array(
      array('InArray', false, array(
       'hay' => array(1), 
       'messages' => 'Please check the consent box'), 
      ) 
     ), 
     'decorators' => array(
      'ViewHelper', 
      'Errors', 
      'Label' => array(
       'placement' => 'append' 
      ) 
     ), 
)); 
+0

我会试试这个。但有没有办法在addElement方法中设置它? – ryy

+0

我用一个例子编辑了我的答案。未经测试,请告诉我,如果它不起作用。 –

+0

我不得不做'decorators'=> array(array('Label',array('placement'=>'APPEND')));谢谢你的指针。 – ryy

0

这是渲染表单元素的代码。

$ this-> form-> name-> renderLabel();