You are here

public function ApiTestForm::validateForm in Rocket.Chat 8

Same name and namespace in other branches
  1. 8.2 modules/rocket_chat_api_test/src/Form/ApiTestForm.php \Drupal\rocket_chat_api_test\Form\ApiTestForm::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/rocket_chat_api_test/src/Form/ApiTestForm.php, line 142
Contains \Drupal\rocket_chat_api_test\Form\ApiTestForm.

Class

ApiTestForm
Class RocketChatSettingsForm.

Namespace

Drupal\rocket_chat_api_test\Form

Code

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

  // All required fields are submitted.
  if (!empty($form_state
    ->getValue('Options'))) {
    $jsonOptions = Json::decode($form_state
      ->getValue('Options'));
    if (!empty($form_state
      ->getValue('Options')) && is_null($jsonOptions)) {

      // Json is wrong.
      $form_state
        ->setErrorByName('Options', $this
        ->t('JSON PARSE ERROR,please check your JSON'));
    }
  }
}