Validation error on term-reference field when ajax'd option is submitted? I get the error "Illegal choice" when I submit a form with a multi-select option that was freshly created via ajax.  Workflow is like this:


User loads node edit form
User needs to select a non-existant job title (job titles are drupal taxonomy terms)
User presses my custom ajax button that (1)takes their new title, (2) adds their new title as a drupal term, (3) updates the form in the browser, (4) selects the new title


When I submit the form, drupal doesn't seem to see that the new title has a corresponding (therefore valid) TID and errors out in the validation.

I tried creating custom validation on the title element, but despite passing that validation, drupal still does its own check, which fails.  

Anyone know how to work around this?
Drupal checks the integrity of the form to make sure submitted values match up with the available options when the form was built; it's a security feature. Manipulating the form on the client-side, without informing the backend that something has changed, causes the integrity check to fail.

Rather than work around it (which is possible but messy), I'd recommend using the AJAX functionality already built into the form API.

The AJAX Forms in Drupal 7 page, FAPI AJAX reference and the AJAX Example in the Examples module are excellent resources for learning about this.