In case someone is wondering, I use array notation to declare all my elements in my forms, and in zend framework 2 - by default, selected in the switch, you must add the attribute value and make it the option_value key that you want to choose by default:
// Inside your constructor or init method for your form // $this->add( [ 'type' => 'Radio', 'name' => 'some_radio', 'options' => [ 'value_options' => [ 'opt1' => 'Radio option 1', 'opt2' => 'Radio option 2' ] ], 'attributes' => [ 'value' => 'opt1' // This set the opt 1 as selected when form is rendered ] ] );
I found some examples a bit confusing because they used numeric keys in the parameter values (0, 1), so when I saw "value" => 1, it was not obvious to me that it was the key in the value_options array. Hope this helps someone.
source share