You are here

public function WebformDevelSubmissionApiForm::validateForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_devel/src/Form/WebformDevelSubmissionApiForm.php \Drupal\webform_devel\Form\WebformDevelSubmissionApiForm::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

modules/webform_devel/src/Form/WebformDevelSubmissionApiForm.php, line 136

Class

WebformDevelSubmissionApiForm
Form used to test programmatic submissions of webforms.

Namespace

Drupal\webform_devel\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValue('values');

  // Check if the webform is open to new submissions.
  $webform = Webform::load($values['webform_id']);
  if (!$webform) {
    $form_state
      ->setErrorByName('values', $this
      ->t('Webform %webform_id not found.', [
      '%webform_id' => $values['webform_id'],
    ]));
    return;
  }
  $is_open = WebformSubmissionForm::isOpen($webform);
  if ($is_open !== TRUE) {
    $form_state
      ->setErrorByName('values', $is_open);
  }

  // Validate values.
  if ($errors = WebformSubmissionForm::validateFormValues($values)) {
    foreach ($errors as $error) {
      $form_state
        ->setErrorByName('values', $error);
    }
  }
}