creating a custom submit function for the form of mymodule
/**
* Implements hook_form_submit()
*/
function mymodule_form_submit($form, &$form_state){
$new_user = drupal_anonymous_user();
// removed basic user fields here to make it more clear
// save taxonomy checkbox field
foreach ($form_state['values']['third']['field_functioncat'] as $key => $value) {
if($value > 0){
$new_user->field_functioncat[LANGUAGE_NONE][$key]['tid'] = $value;
}
}
// save text field
$new_user->field_firstname[LANGUAGE_NONE][0]['value'] = $form_state['values']['first']['field_firstname'];
user_save($new_user);
}
Above code works but I'm having trouble saving the autocomplete field.
What I'm trying:
// get value of the form
$tid = taxonomy_get_term_by_name($form_state['values']['first']['field_city'], 'field_city');
// get the first array value and then the tid of the left over object:
$tid = reset($tid)->tid;
// save field to user profile
$new_user->field_city[LANGUAGE_NONE][$tid]['tid'] = $tid;
This works for existing terms, but when I put in a new term it can't get the id of the term because that term name is not created?
How do I create the term name and get the tid to submit it to the user creation?
note: I've created the field_city as taxonomy term and linked it to the user profile so it's visible and editable in on the user edit profile page.