0
votes

I set this zend form element radio:

    //nationality
    $this->addElement('radio', 'nationality', array('label' => 'F_NATIONALITY', 'separator' => ' ', 'label_class' => 'l_radio', 'required' => true));
    $this->nationality->addMultiOption('italian', 'F_NATIONALITY_IT');
    $this->nationality->addMultiOption('foreign', 'F_NATIONALITY_FO');
    $this->nationality->addValidator('NotEmpty');

and this is the output:

enter image description here

what you do not understand is why I can not show the error message even if I set the attribute 'required' validator and 'NotEmpty'?

Thanks

1
i tested your code and it seems to work for me (an error message was shown after submitting the form). can you provide a little more context? maybe the error is somewhere else ... - Michael Osl
What are the decorators for that element? Likely you are missing the Errors decorator. Try var_dump($this->nationality->getDecorators()); and see what that returns. - drew010

1 Answers

0
votes
$nationality= new Zend_Form_Element_Radio('nationality');
        $nationality->setLabel('Nationality:')
           ->setRequired(true)
               ->addMultiOptions(array(
                            'italian' => 'Italian',
                            'foreign' => 'Foreign' 
                                ))
                   ->setSeparator('  ');
           //->setDecorators(array('ViewHelper','Label', 'Errors', array('HtmlTag', array('tag' => 'p'))));

The above code will create Nationality radio button with two options italian and foreign.