Contao\Widget::addError PHP Method

addError() public method

Add an error message
public addError ( string $strError )
$strError string The error message
    public function addError($strError)
    {
        $this->class = 'error';
        $this->arrErrors[] = $strError;
    }

Usage Example

 /**
  * Process a custom date regexp on a widget.
  *
  * @param string $rgxp   The rgxp being evaluated.
  *
  * @param string $value  The value to check.
  *
  * @param Widget $widget The widget to process.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public static function processCustomDateRegexp($rgxp, $value, $widget)
 {
     if ('MetaModelsFilterRangeDateRgXp' !== $rgxp) {
         return;
     }
     $format = $widget->dateformat;
     if (!preg_match('~^' . Date::getRegexp($format) . '$~i', $value)) {
         $widget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['date'], Date::getInputFormat($format)));
     } else {
         // Validate the date (see https://github.com/contao/core/issues/5086)
         try {
             new Date($value, $format);
         } catch (\OutOfBoundsException $e) {
             $widget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $value));
         }
     }
 }