To show the user the saved option, we're supposed to pass in the value, except that's not the setting that's being returned from qa_post_text. The information being returned qa_post_text is the tag.
Existing code:
function form_select($field, $style)
{
$this->output('<SELECT '.@$field['tags'].' CLASS="qa-form-'.$style.'-select">');
foreach ($field['options'] as $tag => $value)
$this->output('<OPTION VALUE="'.$tag.'"'.(($value==@$field['value']) ? ' SELECTED' : '').'>'.$value.'</OPTION>');
$this->output('</SELECT>');
}
My suggestion:
function form_select($field, $style)
{
$this->output('<SELECT '.@$field['tags'].' CLASS="qa-form-'.$style.'-select">');
foreach ($field['options'] as $tag => $value)
$this->output('<OPTION VALUE="'.$tag.'"'.(($tag==@$field['tag']) ? ' SELECTED' : ''). '>'.$value.'</OPTION>');
$this->output('</SELECT>');
}
This is important because the tag is typically an ID which doesn't change, while the value could be a user friendly name, which could change.
When the user saves the form, qa_post_text returns the tag of the item selected. It's the tag that's stored in qa_opt, not the value. So to select the correct item in the dropdown, we need to use the tag that we stored in the db.