You are here

public function SinglePageSiteConfigForm::validateForm in Single Page Site 8

Same name and namespace in other branches
  1. 2.x src/Form/SinglePageSiteConfigForm.php \Drupal\single_page_site\Form\SinglePageSiteConfigForm::validateForm()
  2. 2.0.x src/Form/SinglePageSiteConfigForm.php \Drupal\single_page_site\Form\SinglePageSiteConfigForm::validateForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/SinglePageSiteConfigForm.php, line 182

Class

SinglePageSiteConfigForm
Class SinglePageSiteConfigForm @package Drupal\single_page_site\Form

Namespace

Drupal\single_page_site\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);

  // Validate menu class on special chars.
  $menu_class = $form_state
    ->getValue('menuclass');
  if (preg_match('/[^A-Za-z0-9#.-]/', $menu_class)) {
    $form_state
      ->setErrorByName('menuclass', t('"Menu Class/Id" contains forbidden chars. Only a-z, #, ., - allowed.'));
  }

  // Validate class on non alphapetic chars.
  $class = $form_state
    ->getValue('class');
  if (preg_match('/[^A-Za-z0-9-]/', $class)) {
    $form_state
      ->setErrorByName('class', t('"Menu item selector"  contains forbidden chars. Only a-z, - allowed.'));
  }

  // Validate tag on special chars.
  $tag = $form_state
    ->getValue('tag');
  if (preg_match('/[^A-Za-z0-9]/', $tag)) {
    $form_state
      ->setErrorByName('tag', t('"Tag" contains special characters.'));
  }
}