form with taxonomy autocomplete widget throws error upon submit: Invalid argument supplied for foreach() I have a custom form with this field in it:

$form['first']['field_city'] = array(
    '#title' =&gt; t('Woonplaats'),
    '#type' =&gt; 'textfield',
    '#size' =&gt; 25,
    '#autocomplete_path' =&gt; 'taxonomy/autocomplete/field_city',
    '#element_validate' =&gt; array('taxonomy_autocomplete_validate'),
    '#required' =&gt; TRUE,
);


I'm trying to use the autocomplete tagging widget to use with an existing taxonomy vocabulary on this form.
It works fine tags are loaded when I start typing but if I submit the form I get the following Warning:

Warning: Invalid argument supplied for foreach() in taxonomy_autocomplete_validate()


resulting in this error and the wsod (white screen of death)

   PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 2: 
SELECT base.tid AS tid, base.vid AS vid, base.name AS name, base.description AS description, base.format AS format, base.weight AS weight, v.machine_name AS vocabulary_machine_name FROM {taxonomy_term_data} base INNER JOIN {taxonomy_vocabulary} v ON base.vid = v.vid WHERE (base.name LIKE :db_condition_placeholder_0 ESCAPE '\\') AND (base.vid IN ()) ; Array ( [:db_condition_placeholder_0] =&gt; Amsterdam )


I think I'm missing something in the form decleration or made a mistake somewhere. 
So what's wrong with it? Thanks!

some suggestion is that the machine_name of the field might be wrong. ( the machine name is actually stad when I look in the taxonomy in the admin UI).
I'm pretty sure this error will be coming from the following loop in taxonomy_autocomplete_validate()

 // Collect candidate vocabularies.
    $field = field_widget_field($element, $form_state);
    $vocabularies = array();
    foreach ($field['settings']['allowed_values'] as $tree) {
      if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
        $vocabularies[$vocabulary-&gt;vid] = $vocabulary;
      }
    }


which is collecting the vocabularies allowed for the field, check:


Field is set to be a term reference
Field has at least one allowed vocabulary set
field_city is the correct machine name of the field in question