1

I need to change the first value (the default one) in one of my taxonomy based dropdown menus. It is currently set to '- CHose a value -', and I need it to be changed to: '- Chose city -'.

I thought I might use form_alter for this, But I cant get further then to the correct form_id.

What to I do next?

2

First you need to find out where the element that you're trying to manipulate is within the form array. The best way to do that is to install the Devel module and use the dpm() function to inspect the $form variable:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'my_form') {
    dpm($form);
  }
}

When you see the variable outputted to the message you can drill down until you find the particular element. Note the keys of the element's parents in the array as you'll need them too.

If this is a node form and the taxonomy list is provided by a term reference field the actual form element will be found somewhere like this:

$form['field_field_name']['und'][0]['tid']

Using that example your form alter would look like this:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'my_form') {
    $form['field_field_name']['und'][0]['tid']['#options'][0] = '- Choose City -';
  }
}

Again you'll have to confirm using dpm() whether 0 is the right array key for the default select option that you're changing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.