n Drupal 8 - disable form field | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

Code snippet that can be used to disable form field in drupal 8.

function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
  if ($form_id == "user_register_form") {
    $form['account']['notify']['#attributes']['disabled'] = 'disabled';
    // or
    $form['account']['notify']['#attributes']['readonly'] = 'readonly';



Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts


Page Facebook