You are here

function botcha_set_form_id_setting in BOTCHA Spam Prevention 7

Same name and namespace in other branches
  1. 6 botcha.inc \botcha_set_form_id_setting()

Helper function for adding/updating a BOTCHA point.

Parameters

$form_id the form ID to configure.:

botcha_type the setting for the given form_id, can be::

  • 'none' to disable BOTCHA,
  • 'default' to use the default challenge type
  • NULL to remove the entry for the BOTCHA type

Return value

nothing

16 calls to botcha_set_form_id_setting()
BotchaAdminTestCase::testBotchaPlacementCacheFlushing in ./botcha.test
Test the BOTCHA placement flushing.
BotchaAdminTestCase::testBotchaPointSettingGetterAndSetter in ./botcha.test
Test the BOTCHA point setting getter/setter.
BotchaAdminTestCase::testUntrustedUserPosting in ./botcha.test
BotchaSessionReuseAttackTestCase::testBotchaSessionReuseAttackDetectionOnCommentPreview in ./botcha.test
BotchaSessionReuseAttackTestCase::testBotchaSessionReuseAttackDetectionOnLoginForm in ./botcha.test

... See full list

File

./botcha.inc, line 29
General BOTCHA functionality and helper functions.

Code

function botcha_set_form_id_setting($form_id, $botcha_type) {

  //watchdog('debug','IN botcha_set_form_id_setting form_id='.$form_id.' botcha_type='.$botcha_type);
  if ($botcha_type == 'none') {
    db_delete('botcha_points')
      ->condition('form_id', $form_id)
      ->execute();
    $id = db_insert('botcha_points')
      ->fields(array(
      'form_id' => $form_id,
      'botcha_type' => NULL,
    ))
      ->execute();
  }
  elseif ($botcha_type != NULL) {
    db_delete('botcha_points')
      ->condition('form_id', $form_id)
      ->execute();
    $id = db_insert('botcha_points')
      ->fields(array(
      'form_id' => $form_id,
      'botcha_type' => $botcha_type,
    ))
      ->execute();
  }
  else {
    db_delete('botcha_points')
      ->condition('form_id', $form_id)
      ->execute();
  }

  //  else {
  //    drupal_set_message(t('Failed to set a BOTCHA type for form %form_id: could not interpret value "@botcha_type"',
  //      array('%form_id' => $form_id, '@botcha_type' => (string) $botcha_type)), 'warning');
  //  }
}