How to display a warning message I have a form with a required checkbox.

If the box is not checked and I confirm my form, I receive a warning with Chrome (see the screenshot).

How to display a warning message in drupal ?

In my module, I add code to display a Drupal warning. Why is not it displayed ?

&lt;?php

namespace Drupal\commerce_agree_cgv\Plugin\Commerce\CheckoutPane;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;

/**
 * Provides the completion message pane.
 *
 * @CommerceCheckoutPane(
 *   id = "agree_cgv",
 *   label = @Translation("Agree CGV"),
 *   default_step = "review",
 * )
 */
class AgreeCGV extends CheckoutPaneBase implements CheckoutPaneInterface {

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &amp;$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);

    if (!$form_state-&gt;getErrors()) {
      $values = $form_state-&gt;getValue($form['#parents']);
      $this-&gt;t('You must agree with the terms before continuing.');
    }
  }

  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &amp;$complete_form) {
    $store_name = $this-&gt;order-&gt;getStore()-&gt;getName();
    $store_id = $this-&gt;order-&gt;getStoreId();
    $pane_form['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $attributes = [
      'attributes' =&gt; [
        'modal-title' =&gt; $this-&gt;t('Terms and conditions'),
        'class' =&gt; 'use-ajax',
        'data-dialog-type' =&gt; 'modal',
        'data-dialog-options' =&gt; Json::encode([
          'width' =&gt; auto,
        ]),
      ],
    ];
    $link = Link::fromTextAndUrl(
      $this-&gt;t('the general terms and conditions of the store "@store_name"', ['@store_name' =&gt; $store_name]),
      Url::fromUri("internal:/store/$store_id/cgv", $attributes)
    )-&gt;toString();
    $pane_form['cgv'] = [
      '#type' =&gt; 'checkbox',
      '#default_value' =&gt; FALSE,
      '#title' =&gt; $this-&gt;t('I have read and accept @cgv.', ['@cgv' =&gt; $link]),
      '#required' =&gt; TRUE,
      '#weight' =&gt; $this-&gt;getWeight(),
    ];
    return $pane_form;
  }

  /**
   * {@inheritdoc}
   */
  public function validatePaneForm(array &amp;$pane_form, FormStateInterface $form_state, array &amp;$complete_form) {
    $values = $form_state-&gt;getValue($pane_form['#parents']);
    if (!$values['cgv']) {
      $form_state-&gt;setError($pane_form, $this-&gt;t('You must agree with the terms before continuing.'));
    }
  }

}
That’s the browser validation message appearing. If you want to show Drupal messages only, you need to set the no-validate attribute on the form tag itself so browsers ignore it. Drupal will still run validation on submission.