While trying to utilize the phalcon form component, I found that the Radio element is not at all useful.
In HTML, if you want to create a radio group, you give the elements the same name. ie.
<input type="radio" name="sex" value="male">Male<br> <input type="radio" name="sex" value="female">Female
In phalcon, a radio element is just an extension of the Element base class. Since we use the element name/id as a key, we create each option in the radio group as a seperate form element in phalcon.
// News Letter $newsLetterYes = new Radio('newsLetterY', array('value' => 'yes', 'name' => 'newsLetter')); $newsLetterYes->setLabel('Yes'); $newsLetterNo = new Radio('newsLetterN', array('value' => 'no', 'name' => 'newsLetter')); $newsLetterNo->setLabel('No');
It is not possible to add validators to the group itself, so we would have to add validators to each option. I think the Radio element should be treated similar to a select element, in that it has series of options with values. That way a user could specify the options in an array to the constructor, similar to the select element.