Question

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'),
 ));
Was it helpful?

Solution

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

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top