Modal form - cant set error message, and no message for required field In a modal form, i've got e email field that is required. 


when the field is wrong, a error message is well displayed
when the field is empty, $form_state->hasAnyErrors() is true but there is no error message
when i whant to set the error message in the form validation function, it's stay empty !  


in BuildForm : 

  $form['email'] = array(
            '#type' =&gt; 'email',
            '#required' =&gt; true,
            '#attributes' =&gt; [
                'placeholder' =&gt; t('Your email'),
                "data-nluid" =&gt; $nluid
            ],
        );
$form['actions']['submit'] = [
                '#type' =&gt; 'submit',
                '#value' =&gt; t('Suscribe'),
                '#ajax' =&gt; [
                    'callback' =&gt; '::submitModalFormAjax',
                    'wrapper' =&gt; 'newsletter_add_modal', 
                    'event' =&gt; 'click'
                ]
            ];


in validateForm

 public function validateForm(array &amp;$form, FormStateInterface $form_state) {
        $emailValue = $form_state-&gt;getValue("email");
        if (!\Drupal::service('email.validator')-&gt;isValid($emailValue) || trim($emailValue) == "") {

         $form_state-&gt;setErrorByName('email', "Email is required and must be valid");    
         //binding form_state-&gt;getError($form['email']) show empty string
        }
    }


in submitModalFormAjax

 // If there are any form errors, re-display the form.
        if ($form_state-&gt;hasAnyErrors()) { 
            $response-&gt;addCommand(new ReplaceCommand('#newsletter_add_modal', $form));
        } else {
 // else, exec success behavior


What am I doing wrong?
I know i'm a bit late but the problem is that the email field is required.
Required fields may not be empty, otherwise it will throw an error.

If you wish to show an error message you need a form element to catch these messages.

 $form['status_messages'] = [
      '#type' =&gt; 'status_messages',
      '#weight' =&gt; -10,
    ];