Skip to main content
Category:

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

Search

Page Facebook