How would I set default of a custom select list? I created a table of branch addresses that I use to populate the select list. I also pull the users' branch from LDAP (profile field). How do I select it as default? The value of the tag contains data of all the fields. Thanks for your help.
<?php
function uc_approval_select_branch($uid, $type = 'billing', $onchange = '', $title = NULL, $icon_suffix = FALSE) {
global
$user;
$user_info = user_load(array('uid'=>$user->uid));
$branches = uc_approval_get_branches($uid, $type);
if(!
is_array($branches) || count($branches) == 0) { return NULL; }
$options = array('0' => t('Select one...'));
foreach ($branches as $branch) {
$options[drupal_to_js($branch)] = check_plain($branch['name']);
// check if the branch matches
if ($branch['name'] == $user_info->profile_branch) {
$default = $options[drupal_to_js($branch)]; // set the $default
}
}
$select = array(
'#type' => 'select',
'#title' => is_null($title) ? t('Branches') : $title,
'#options' => $options,
'#attributes' => array('onchange' => $onchange),
'#suffix' => $icon_suffix ? uc_store_get_icon('file:address_book', FALSE, 'address-book-icon') : NULL,
'#weight' => -5,
'#default_value' => $default, // apply the default
);
return
$select;
}
?>By the way, I tried
<?php
$form['panes']['delivery']['delivery_branch_select']['#default_value'] = $user_info->profile_branch;
?>but it did not work.
