You are here

public function WishlistEmailForm::validateForm in UC Wish List 8

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/WishlistEmailForm.php, line 57

Class

WishlistEmailForm

Namespace

Drupal\uc_wishlist\Form

Code

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

  // Exploding the emails id of the recpients.
  $emails = explode(',', $form_state->getValue['recipients']);
  $emails = array_filter($emails);
  foreach ($emails as $email) {
    $email = trim($email);
    if (strlen($form_state
      ->getValue('recipients')) < 5) {
      $form_state
        ->setErrorByName('recipients', $this
        ->t('Recipients field is required.'));
    }
    if ($email != '' && !valid_email_address($email)) {

      // Generating error.
      $form_state
        ->setError('emails', $this
        ->t('%email is not a valid email address', [
        '%email' => $email,
      ]));
    }
  }
}