2 added 715 characters in body
source | link

I want to disable custom field in form, my field name is field_course_display_ref and it is entity reference.
I try $form['field_course_display_ref']['und']['#attributes']['disabled'] = 'disabled'; but when form submit it return the field_course_display_ref is required , I also try $form['field_course_display_ref']['#disabled'] = TRUE; but not work and field not disabled( user can change it).
also I try to remove #require with $form['field_course_display_ref']['und']['#required']=FALSE; but nothing happen and when form submit, return the field_course_display_ref is required .

How can I disable required field in form ?

I create form in callback of menu ,part of my code

function cdigitdev_pre_register_ym() {
    global $user;
    drupal_add_js(drupal_get_path('module', 'cdigitdev') . '/js/cdigitdev.js', array('scope' => 'footer'));
    $nid = intval(arg(2));
    $productId = intval(arg(3)); //it will set to null if arg(3) not set ; equal to $productId=arg(3)? intval(arg(2)):NULL;
    module_load_include('inc', 'node', 'node.pages');
    $form = node_add('pre_register');
    $form['field_course_schedules']['#disabled'] = TRUE;
    //$form['field_course_schedules']['und']['#disabled'] = TRUE;
.
.
.
.
    return drupal_render($form);
} 

I want to disable custom field in form, my field name is field_course_display_ref and it is entity reference.
I try $form['field_course_display_ref']['und']['#attributes']['disabled'] = 'disabled'; but when form submit it return the field_course_display_ref is required , I also try $form['field_course_display_ref']['#disabled'] = TRUE; but not work and field not disabled( user can change it).
also I try to remove #require with $form['field_course_display_ref']['und']['#required']=FALSE; but nothing happen and when form submit, return the field_course_display_ref is required .

How can I disable required field in form ?

I want to disable custom field in form, my field name is field_course_display_ref and it is entity reference.
I try $form['field_course_display_ref']['und']['#attributes']['disabled'] = 'disabled'; but when form submit it return the field_course_display_ref is required , I also try $form['field_course_display_ref']['#disabled'] = TRUE; but not work and field not disabled( user can change it).
also I try to remove #require with $form['field_course_display_ref']['und']['#required']=FALSE; but nothing happen and when form submit, return the field_course_display_ref is required .

How can I disable required field in form ?

I create form in callback of menu ,part of my code

function cdigitdev_pre_register_ym() {
    global $user;
    drupal_add_js(drupal_get_path('module', 'cdigitdev') . '/js/cdigitdev.js', array('scope' => 'footer'));
    $nid = intval(arg(2));
    $productId = intval(arg(3)); //it will set to null if arg(3) not set ; equal to $productId=arg(3)? intval(arg(2)):NULL;
    module_load_include('inc', 'node', 'node.pages');
    $form = node_add('pre_register');
    $form['field_course_schedules']['#disabled'] = TRUE;
    //$form['field_course_schedules']['und']['#disabled'] = TRUE;
.
.
.
.
    return drupal_render($form);
} 
1
source | link

how to disable required field in form

I want to disable custom field in form, my field name is field_course_display_ref and it is entity reference.
I try $form['field_course_display_ref']['und']['#attributes']['disabled'] = 'disabled'; but when form submit it return the field_course_display_ref is required , I also try $form['field_course_display_ref']['#disabled'] = TRUE; but not work and field not disabled( user can change it).
also I try to remove #require with $form['field_course_display_ref']['und']['#required']=FALSE; but nothing happen and when form submit, return the field_course_display_ref is required .

How can I disable required field in form ?