adding a field to the form during form_validate I am working on a node form in which my users can add sport-teams (which I'll handle through a taxonomy) that are related to the node (say it's a blog-entry about your local rugby-team and you want to relate it to the team's taxonomy entry). To each team entry, I also have a db-table with a corresponding zip-code of the teams headquarter (say your local rugby team comes from cardiff). 

Now the users can also add teams, that are currently not in the taxonomy list (through the use of taxonomy-autocomplete (i.e. tagging)). When that happens, during form_validate, I fire a form_set_error() and ask the user to type in the City the team is coming from. 

In effect, I want to add a field to the form during form_validate. But how do I do that?

I tried, to no avail, adding the following to the $form variable in the form_validate function:

$form['field_new_team_location'][$i] = array(
'#type' =&gt; 'textfield',
'#title' =&gt; t('new team location'),
'#default_value' =&gt; $node-&gt;title,
'#size' =&gt; 60,
'#maxlength' =&gt; 128,
'#required' =&gt; TRUE,
'#description' =&gt; t('description')
);


EDIT Alas, although Charlie S' answer helped me to put up a field during validation (read: the html gets displayed; I can write in them), but it seems I cannot access it in a follow-up validation. In fact, when I hit save again, neither $form nor $form_state have the newly created fields in them! Any help accessing my fields is much appreciated!

2nd EDIT With what Charlie S said, it works. One thing that holding me up was that the form only gets rebuilt when no error messages are being cast. In other words, every required field has to be supplied before the form gets rebuilt and the user is able to input something in the new fields.
In form_validate(), make sure your arguments are being passed by reference:

myform_validate(&amp;$form, &amp;$form_state)


Then the last thing you should have in _validate() is:

$form_state['rebuild'] = TRUE;


Edit: You will want to handle the actual adding of the element in the form builder. This is tested and working:

function customform_custom_form($form, $form_state) {
  $form['field_a'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'Field A',
    '#required' =&gt; TRUE,
    '#weight' =&gt; 1,
  );      

  // Add field b depending on the value of field a.
  if (isset($form_state['input']) &amp;&amp; !empty($form_state['input']['field_a'])) {
    $form['field_b'] = array(
      '#type' =&gt; 'textfield',
      '#title' =&gt; 'Field B',
      '#weight' =&gt; 2,
    );
  }

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; 'Submit',
    '#weight' =&gt; 99,
  );

  return $form;
}

function customform_custom_form_validate(&amp;$form, &amp;$form_state) {
  if (empty($form_state['values']['field_b'])) {
    form_set_error('field_b', 'Please enter something in Field B.');
    $form_state['rebuild'] = TRUE;
  }
}

function customform_custom_form_submit(&amp;$form, &amp;$form_state) {
  drupal_set_message('You entered ' . $form_state['values']['field_b'] . ' for Field B.');
}