Magento 1.9 Admin Form – How to Set Field Select Option Value Selected

adminformmagento-1.9select

i set the value for select field in admin form like this

$categories = Mage::getModel('test_yeezy/test')->getCollection();
        foreach ($categories as $category) {
          $values[] = array(
                        'value'     => $category->getCategoryId(),
                        'label'     => $category->getCategoryName()
                      );
        }

$fieldset->addField(
            'attribute_magento',
            'select',
            array(
                'name'   => 'attribute_magento0',
                'container_id' => 'attribute-magento0',
                'values' => $values,
        ));

the first value selected always the first record of the data, is there anyway to make the value selected first if it's not the first data, for example in html goes like this:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw" selected>VW</option>
  <option value="audi">Audi</option>
</select> 

Best Answer

If I understand your question, try this way:

Adding 'value' => 'vw' after 'values' => $values in your addField

$fieldset->addField(
        'attribute_magento',
        'select',
        array(
            'name'   => 'attribute_magento0',
            'container_id' => 'attribute-magento0',
            'values' => $values,
            'value' => 'vw',
    ));