You are here

function tfa_basic_form_validate in TFA Basic plugins 7

Validation for TFA admin settings alter.

1 string reference to 'tfa_basic_form_validate'
tfa_basic_form_tfa_admin_settings_alter in ./tfa_basic.module
Implements hook_form_FORM_ID_alter().

File

./tfa_basic.module, line 670

Code

function tfa_basic_form_validate($form, &$form_state) {
  $login = array();
  $values = $form_state['values'];
  if (!empty($values['tfa_login'])) {
    foreach ($values['tfa_login'] as $key => $enabled) {
      if ($enabled) {
        $login[] = $key;
      }
    }
    if (!empty($login) && in_array('tfa_basic_trusted_browser', $login) && empty($values['tfa_basic_cookie_domain'])) {
      form_set_error('tfa_basic_cookie_domain', t('Cookie domain is required if Trusted Browser plugin is enabled.'));
    }
  }
  if (!empty($values['tfa_fallback']) && (!empty($values['tfa_fallback']['tfa_basic_sms']['enable']) || $values['tfa_validate'] === 'tfa_basic_sms')) {
    if (empty($values['tfa_basic_twilio_account_sid'])) {
      form_set_error('tfa_basic_twilio_account_sid', t('Account SID is required if Twilio SMS plugin is enabled.'));
    }
    if (empty($values['tfa_basic_twilio_account_token'])) {
      form_set_error('tfa_basic_twilio_account_token', t('Account token is required if Twilio SMS plugin is enabled.'));
    }
    if (empty($values['tfa_basic_twilio_account_number'])) {
      form_set_error('tfa_basic_twilio_account_number', t('Account number is required if Twilio SMS plugin is enabled.'));
    }
    if (empty($values['tfa_basic_twilio_message_text'])) {
      form_set_error('tfa_basic_twilio_message_text', t('Message text is required if Twilio SMS plugin is enabled.'));
    }
    elseif (strpos($values['tfa_basic_twilio_message_text'], '!code') === FALSE) {
      form_set_error('tfa_basic_twilio_message_text', t('Message text must include token !code.'));
    }
    $phone_field = variable_get('tfa_basic_phone_field', '');
    if ($phone_field !== FALSE && empty($values['tfa_basic_phone_field'])) {
      form_set_error('', t('An account field for mobile number storage is required to use the Twilio SMS plugin. Consult TFA Basic README.txt for more info.'));
    }
  }
}