欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

cck 字段 设置禁用 form alter 或者 设置 class "How to set the disabled or readonly attribute of a CCK field" "Unable to add '#attributes' or use '#disabled' = true via hook_form_alter()"有大用

shiping1 的头像
function my_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
    $form['#after_build'][] = 'my_form_process';
  }
}
function my_form_process($form, &$form_state) {
  my_fix_disabled($form['field_myfiled']);
  return $form;
}
function my_fix_disabled(&$elements) {
  foreach (element_children($elements) as $key) {
    if (isset($elements[$key]) && $elements[$key]) {
      // Recurse through all children elements.
      my_fix_disabled($elements[$key]);
    }
  }
  if (!isset($elements['#attributes'])) {
    $elements['#attributes'] = array();
  }
  $elements['#attributes']['disabled'] = 'disabled';
$elements['#attributes']['class'] = 'aaaaa';
}

来自 https://www.drupal.org/node/336355
普通分类: