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['field_new_team_location'][$i] = array( '#type' => 'textfield', '#title' => t('new team location'), '#default_value' => $node->title, '#size' => 60, '#maxlength' => 128, '#required' => TRUE, '#description' => 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_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.