You are here

public function AbjsTestForm::validateTest in A/B Test JS 8

Same name and namespace in other branches
  1. 2.0.x src/Form/AbjsTestForm.php \Drupal\abjs\Form\AbjsTestForm::validateTest()

Validate the form.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: The state of forms.

File

src/Form/AbjsTestForm.php, line 389

Class

AbjsTestForm
Class for build form test.

Namespace

Drupal\abjs\Form

Code

public function validateTest(array &$form, FormStateInterface $form_state) {
  for ($i = 0; $i < count($form_state
    ->getValue([
    'experiences_fieldset',
    'experiences',
  ])); $i++) {
    if (!preg_match('#^[0-9./]+$#', $form_state
      ->getValue([
      'experiences_fieldset',
      'experiences',
    ])[$i]['fraction'])) {
      $form_state
        ->setErrorByName("experiences_fieldset][experiences][{$i}][fraction", $this
        ->t('Invalid character used in Experience @i Fraction. Only numbers, decimals, and slashes are allowed. Other characters, including spaces, are not allowed.', [
        '@i' => $i + 1,
      ]));
    }
  }
}