You are here

function seotools_setup_1_form_validate in Drupal SEO Tools 7

File

./seotools.setup.inc, line 165
Admin page callback for the seotools module.

Code

function seotools_setup_1_form_validate($form, &$form_state) {
  $values = $form_state['values'];

  // validate Google Analytics account
  if (module_exists('googleanalytics')) {
    if (!isset($values['googleanalytics_set']) && !preg_match('/^UA-\\d{4,}-\\d+$/', $form_state['values']['googleanalytics_account'])) {
      form_set_error('googleanalytics_account', t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.'));
    }
  }

  // validate WordStream account
  if (module_exists('wordstream')) {
    if (!isset($values['wordstream_set'])) {
      $wordstream = wordstream_include_api_class($values['wordstream_username'], $values['wordstream_password']);
      $account = 0;
      if ($wordstream) {
        $ret = $wordstream
          ->getAPICredits();
        if ($ret->credits_per_month) {
          $account = 1;
        }
      }
      if (!$account) {
        form_set_error('wordstream_username', t('Unable to log in to WordStream. Please enter a valid WordStream API username and password.'));
      }
    }
  }

  // validate Google Analytics account
  if (!isset($values['alchemy_set']) && !preg_match('/^([A-Fa-f0-9]{2}){20}$/', $form_state['values']['alchemy_apikey'])) {
    form_set_error('alchemy_apikey', t('Alchemy API key is invalid.'));
  }
}