Skip to main content
deleted 9 characters in body
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Set the required_error property "required_error" to form elementas in the following code. This is available in Drupal 8.6. For ex-

$form['name'] = [
  '#type' => 'textfield',
  '#size' => 60,
  '#default_value' => $form_state->getValue('name', ''),
  '#required' => TRUE,
  '#required_error' => t('Please select something.'),
];

To make this work, firstly you will have to disable HTML 5HTML5 validation on the form.

$form['#attributes']['novalidate'] = 'novalidate';

Set the property "required_error" to form element. This is available in Drupal 8.6. For ex-

$form['name'] = [
  '#type' => 'textfield',
  '#size' => 60,
  '#default_value' => $form_state->getValue('name', ''),
  '#required' => TRUE,
  '#required_error' => t('Please select something.'),
];

To make this work, firstly you will have to disable HTML 5 validation on the form.

$form['#attributes']['novalidate'] = 'novalidate';

Set the required_error property as in the following code. This is available in Drupal 8.6.

$form['name'] = [
  '#type' => 'textfield',
  '#size' => 60,
  '#default_value' => $form_state->getValue('name', ''),
  '#required' => TRUE,
  '#required_error' => t('Please select something.'),
];

To make this work, you will have to disable HTML5 validation on the form.

$form['#attributes']['novalidate'] = 'novalidate';
Source Link

Set the property "required_error" to form element. This is available in Drupal 8.6. For ex-

$form['name'] = [
  '#type' => 'textfield',
  '#size' => 60,
  '#default_value' => $form_state->getValue('name', ''),
  '#required' => TRUE,
  '#required_error' => t('Please select something.'),
];

To make this work, firstly you will have to disable HTML 5 validation on the form.

$form['#attributes']['novalidate'] = 'novalidate';