I am not sure if this is the most elegant way to do this but it helped me do something that I could not find any other solution for. I was looking for a way to auto select the forum taxonomy on a new forum topic based on the taxonomy of the previous page or the forum to which the topic was supposed to belong to. I had a taxonomy id attached to the url of the add forum topic page. and I needed to use the Taxonomy id to influence the markup inside of the drop down field in the add form.
I copied theme_select into my template.php, changed it to
_select() and decided to rewrite the form_select_options() function which controls output of the select tags.
I changed the reference to form_select_options() to
_form_select_options()
above
_select. I pasted all the code for form_select_options() and changed the name to
_form_select_options()
inside of that I added code to pull the term id out of the url of the page:
$current_url = 'http://' .$_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'];
$curl2 = filter_var($current_url, FILTER_SANITIZE_NUMBER_INT);
added an if statement to set "selected" to options that match the url string:
if ($value_valid && (!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value']))) || $key === ($curl2)) {