1

I am trying to remove two select list items from a form using this code:

function module_r_form_alter(&$form, &$form_state, $form_id)
{     
    if ($form_id == 'forum-node-form') {
        unset($form['edit-taxonomy-forums-und']['#options']['_none']);
        unset($form['edit-taxonomy-forums-und']['#options']['4']);
    }
}

The above code is not working. I would greatly appreciate any help you can give me in working this problem.

2

If the name of your field is edit-taxonomy-forums-und your code should be:

unset($form['edit-taxonomy-forums-und'][LANGUAGE_NONE]['#options']['4']);

Maybe you don't have the correct name of the field. Go to the Manage fields page of your content type (YOUR_SITE/admin/structure/types/manage/YOUR_CONTENT_TYPE/fields) and check the name of the field.

enter image description here

EDIT:

If you read the comments in the answer you will see that the problem was the change of forum_node_form by forum-node-form.

6
  • Thank you for your prompt reply. It still does not work. What I am trying to alter is select list from taxonomy_forums. .
    – Dominick
    Jan 30 '16 at 7:50
  • It works when I remove if ($form_id == 'forum-node-form') {} condiion. But how to specify an id the form is using?
    – Dominick
    Jan 30 '16 at 8:15
  • 1
    Hi @Dominick i think you have to recheck your $form_id. This should be 'forum_node_form' instead of "'forum-node-form'. Jan 30 '16 at 8:49
  • 1
    Sorry to question your answer, but I would integrate the last 2 comments as a "2nd possibility" (or something like that) ... Because that seems to be the real answer to this question ... no? Aug 21 '16 at 7:09
  • 1
    Merci for accepting my advice! Aug 22 '16 at 14:35

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.