Drupal - Programmatically set the default value for a field
Assuming that your form alter function is actually running (which you can confirm with that call to dsm()
), there are actually 2 more levels of array you need to go down to in order to get to the field element:
$form["field_accounts"][LANGUAGE_NONE][0]['value']['#default_value'] = $default;
In Drupal 7 you have a an array of values for each language the field has been translated into (so that fields with multiple/unlimited cardinality can be catered for), and under each of those is in array for the various different field columns. In the majority of cases this will be 'value' but not always (for example an image field has a file id column, alt column etc)
Hope that helps