문제

I am adding a consent checkbox to an existing form. I am not able to render the label to the right of the checkbox. What am I doing wrong?

Please note that the check box has created using $this->addElement( because the rest of the form was created this way.

I thank you in advance.

$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'),
 ));
도움이 되었습니까?

해결책

The default is to prepend the label, but you can change this by modifying the decorator's 'placement' option:

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

Edit: I never use this syntax for decorators but it should be something like this:

$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'
            )
         ),
 ));

다른 팁

This is the code for rendering lable of a form element.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top