ZF-4191: Zend_View_Helper_FormRadio generates improper id attributes for certain values

Description

{quote} $form = new Zend_Form(); $form->addElement('radio', 'myName', array( 'value' => '-1', 'multiOptions' => array( 'inherit' => 'inherit', -1 => 'reset', 1 => 'allow', 0 => 'deny', ), )); $form->populate(array('myName' => 'inherit')); echo $form; {quote}

Generated xhtml:

{quote} inherit
reset
allow
deny {quote}

has two elements with same id "myName-1" (options "-1" and "1"). Also "0 => 'deny'" option is selected, but I have populated form with "'myName' => 'inherit'". Also "0 => 'deny'" option will be selected by default, but I set default "'value' => '-1'".

Comments

Patch to fix the issue. The problem was that dashes were filtered from the id through the use of the alnum filter. In the patch a regex is used to allow both alphanumeric characters and dashes.

Is there any chance of getting this fixed or adding the patch to trunk?

Tidied suggested fix and added more thorough unit test

Fixed in trunk r24059

I've hesitated to merge this into release as it may cause a BC break for those who reference their {{Zend_Form}} elements by id from a view script. Thoughts?

I would patch this.

Merged to release-1.11 in r24160