Custom Validator on Custom Form I see all kinds of examples of how to add a custom validator to an "existing form." Which means, you would use hook_form_alter. I want to add one in the code for my custom form. 

I'm adding this in my buildForm():

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


However, that function never seems to get called. I know naming the validation function "validateForm()" would make it work automatically. But I want to specifically call this validation function because things are going to get more complex. But I seem stuck on this baby step.

  public function buildForm(array $form, FormStateInterface $form_state) {

    $form['#attributes']['novalidate'] = 'novalidate';
    $form['#cache']['max-age'] = 0;
    $form['#action'] = '#email_subscription';
    $form['#validate'][] = 'mycustom_form_validate';

    $form['fname'] = [
      '#type' =&gt; 'textfield',
      '#title' =&gt; $this-&gt;t('First Name'),
      '#maxlength' =&gt; 255,
      '#size' =&gt; 64,
      '#required' =&gt; TRUE,
      '#required_error' =&gt; 'Please provide your first name.',
    ];

    $form['submit'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; $this-&gt;t('send'),
    ];

    return $form;
  }

  public function mycustom_form_validate(array &amp;$form, FormStateInterface $form_state) {
    $valid = $this-&gt;validateEmail($form, $form_state);
    if (!$valid) {
      $form_state-&gt;setErrorByName('email', $this-&gt;t('Invalid email address.'));
    }
  }
You just need to change the line to:

$form['#validate'][] = '::mycustom_form_validate';


Drupal has special handling for that :: prefix (see FormState::prepareCallback), and processes the above to an equivalent callback of:

[$form_object, 'mycustom_form_validate']


Which will correctly resolve to your custom method.