Setup custom required field validation for a field in custom form How can I setup custom required field validation message for a text field in my custom form. I tried below code. But it is not working. It always showing 'Please fill out this field'.

$form['first_name'] = [
  '#type' =&gt; 'textfield',
  '#title' =&gt; $this-&gt;t('First Name'),
  '#default_value' =&gt; $this-&gt;store-&gt;get('first_name') ? $this-&gt;store-&gt;get('first_name') : '',
  '#required_but_empty' =&gt; $this-&gt;t('Please enter First Name'),
  '#required' =&gt; TRUE,
];
How do I add a custom validation to an existing form/field?

If you want to add your custom validator in addition to the default, you will have to add something like this in hook_form_FORM_ID_alter (or similar):

$form['#validate'][] = 'my_test_validate';