-1

Hi I am trying to disable all the form elements of the form. I am using this code to disable the form .

foreach (element_children($form) as $key) {  
  $form[$key]['#disabled'] = TRUE; 
    $form['#attributes'] = array('disabled' => TRUE);
    }
    drupal_set_message("Website is currently in read only mode. During this it is not possible to change site content", "warning");
}

It is working for textbox, radios and submit button but not for the select list and checkbox. What shall I do?

1 Answer 1

0

In a word: recurse.

function _disable_self_and_descendants(&$el) {
  $el['#disabled'] = TRUE;

  foreach (element_children($el) as $key) {
    _disable_self_and_descendants($el[$key]);
  }
}

_disable_self_and_descendants($form);
1
  • this is not working for me. I tried. May be I am doing something wrong Commented May 11, 2017 at 6:27

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.