首页 > 解决方案 > hook_form_user_register_form_alter(更改添加的字段)

问题描述

以下内容无效:(#description 和 #attributes 有效。#required 无效)

function bncreports_form_user_register_form_alter(&$form, FormStateInterface $form_state, $form_id)
{
  $form['account']['mail']['#attributes'] = ['onblur' => "getElementById('edit-name').value=this.value.toLowerCase();"];
  $form['account']['name']['#description'] = 'Use Email address as your username';
  $form['account']['name']['#attributes'] = ['onblur' => 'this.value=this.value.toLowerCase();'];
  $form['field_district']['widget']['#required'] = true;
}

为什么不?

标签: drupal-8

解决方案


推荐阅读