You are here

public function TaxRateFormBase::validate in Ubercart 8.4

File

uc_tax/src/Form/TaxRateFormBase.php, line 131

Class

TaxRateFormBase
Defines the tax rate add/edit form.

Namespace

Drupal\uc_tax\Form

Code

public function validate(array $form, FormStateInterface $form_state) {
  parent::validate($form, $form_state);
  $rate = $form_state
    ->getValue('rate');
  $rate = trim($rate);

  // @todo Would be nice to better validate rate, maybe with preg_match
  if (floatval($rate) < 0) {
    $form_state
      ->setErrorByName('rate', $this
      ->t('Rate must be a positive number. No commas and only one decimal point.'));
  }

  // Save trimmed rate back to form if it passes validation.
  $form_state
    ->setValue('rate', $rate);
}