0

So I have a field that displays locations a list of multi-select locations.

The select has a name of field_location

I want to turn access to this off, and then rebuild the field with a limited list of locations that I will populate.

function rm_report_form_alter(&$form, &$form_state){
    if (arg(0) == 'node' && $form['form_id']['#value'] == 'c_node_form') {
        $form['field_location']['#access'] = FALSE;
    }   
}

The problem: Not sure how to rewrite a multi-select field.

2 Answers 2

1

I think you are searching for the #multiple attribute:

multiple

Used by: select

Description: Indicates whether the user may select more than one item.

Values: TRUE or FALSE

<?php
return array(
  '#type' => 'select',
  '#title' => $title,
  '#default_value' => $value,
  '#options' => $options,
  '#description' => $description,
  '#multiple' => $multiple,
  '#size' => $multiple ? min(12, count($options)) : 0,
  '#weight' => -15,
);
?> 
0

Not 100% sure what you try to accomplish. However the code should look more like this:

function myModule_form_formID_alter(&$form, &$form_state){
    if (arg(0) == 'node') {
        $form['formID']['field_location']['nid']['nid']['#access'] = FALSE;
    }
}

You can use the devel module and its dpm() statement, or even more powerful get Xdebug running on your dev machine to see the full structure of the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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