ASP Classic CAPTCHA Form Object Settings Code Example (BotDetect ASP v4.x; discontinued)

The ASP Classic Captcha form object settings code example shows how to configure BotDetect CAPTCHA challenges by setting Captcha object properties in ASP form source.

Multiple ASP forms within the same ASP website can be protected by BotDetect Captcha challenges: e.g. you could include BotDetect.asp in both your Contact form and Registration form source.

To function properly, separate Captcha challenges placed on each form should have different names (CaptchaId values sent to the Captcha object constructor, Captcha1 and Captcha2 in this example), and can use completely different Captcha settings.

Even multiple Captcha instances placed on the same form won't interfere with each other's validation and functionality. And if a user opens the same page in multiple browser tabs, each tab will independently validate the shown Captcha code.

Shared Captcha settings should always be placed in the CaptchaConfig.asp application configuration file, and only diverging settings set through Captcha object instance properties in form code, to avoid code duplication.

Settings that affect only Captcha container markup generation take effect immediately (changing Captcha.Html output), but settings that affect Captcha challenge (image or sound) generation in separate Http requests need to be saved in ASP Session state when set through Captcha object instance properties in form source, consuming server resources and reverting to defaults when the ASP Session expires.

Please note that if configured values are dynamic (e.g. BD randomization or other function calls in form code), they will be re-calculated only when the form is reloaded (form code is executed). For example, Captcha ImageStyle randomized in ASP form source will not change on each Captcha Reload button click, but only on each form load.

Installed Location

By default, the Classic ASP form object settings code example is installed at:
C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp\WebApp\CaptchaFormObjectSettingsExample

You can also run it from the BotDetect Start Menu:
Programs > Captcha Inc > BotDetect 4 CAPTCHA Component > ASP > Web Applications > Run

Download the BotDetect Classic ASP CAPTCHA Component and run this example

Default.asp

<!-- #include file ="BotDetect.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>BotDetect ASP Classic CAPTCHA Options: Form Object Settings Code 
  Example</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <link type="text/css" rel="Stylesheet" href="<%= CaptchaUrls.LayoutStylesheetUrl() %>" />
  <link type="text/css" rel="Stylesheet" href="StyleSheet.css" />
  <script type="text/javascript" src="<%= CaptchaUrls.ScriptIncludeUrl() %>"><
  /script>
</head>
<body>
  <form method="post" action="" class="column" id="form1">

    <h1>BotDetect ASP Classic CAPTCHA Options: 
    <br /> Form Object Settings Code Example</h1>
    
    <fieldset>
      <legend>ASP Classic CAPTCHA validation</legend>
      <label for="CaptchaCode1">Retype the characters from the picture:</label>
      
      <% 'Adding BotDetect CAPTCHA to the page 
        Dim Captcha1 : Set Captcha1 = (New Captcha)("Captcha1")
        Captcha1.UserInputID = "CaptchaCode1"
        
        Captcha1.CodeLength = 6
        Captcha1.CodeStyleName = "Numeric"
        Captcha1.DisallowedCodeSubstrings = "1,2,3,4,5,00,777,9999"
        Captcha1.CodeTimeout = 300 '5 minutes
        
        Captcha1.ImageStyleName = "SunAndWarmAir"
        Captcha1.ImageWidth = 250
        Captcha1.ImageHeight = 60
        Captcha1.ImageFormat = BDC_ImageFormats("Png")
        
        Captcha1.SoundEnabled = True
        Captcha1.SoundStyleName = "Synth"
        Captcha1.SoundFormat = BDC_SoundFormats("WavPcm8bit8kHzMono")
        Captcha1.SoundRegenerationMode = BDC_SoundRegenerationModes("Limited")
        Captcha1.SoundStartDelay = 100 '0.1 seconds
        
        Captcha1.Locale = "es-MX"
        Captcha1.ImageTooltip = "Custom Mexican Spanish Captcha image tooltip"
        Captcha1.SoundTooltip = "Custom Mexican Spanish Captcha sound icon tooltip"
        Captcha1.ReloadTooltip = "Custom Mexican Spanish Captcha reload icon tooltip"
        Captcha1.HelpLinkUrl = "custom-mexican-spanish-captcha-help-page.html"
        Captcha1.HelpLinkText = "Custom Mexican Spanish Captcha help link text"
        
        Captcha1.ReloadEnabled = True
        Captcha1.UseSmallIcons = False
        Captcha1.UseHorizontalIcons = False
        Captcha1.SoundIconUrl = ""
        Captcha1.ReloadIconUrl = ""
        Captcha1.IconsDivWidth = 27
        Captcha1.HelpLinkEnabled = True
        Captcha1.HelpLinkMode = BDC_HelpLinkModes("Text")
        Captcha1.TabIndex = -1
        Captcha1.AdditionalCssClasses = "class1 class2 class3" 
        Captcha1.AdditionalInlineCss = "border: 4px solid #fff; background-color:#f8f8f8;" 
        
        Captcha1.AddScriptInclude = False
        Captcha1.AddInitScript = True
        Captcha1.AutoUppercaseInput = True
        Captcha1.AutoFocusInput = True
        Captcha1.AutoClearInput = True
        Captcha1.AutoReloadExpiredCaptchas = True
        Captcha1.AutoReloadTimeout = 7200 '2 hours
        Captcha1.RemoteScriptEnabled = True 
        
        Response.Write Captcha1.Html 
      %>
      
      <div class="validationDiv">
        <input type="text" id="CaptchaCode1" name="CaptchaCode1" />
        <% 'CAPTCHA user input validation (only if the form was sumbitted)
          If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
            Dim isHuman1 : isHuman1 = Captcha1.Validate()
            If Not isHuman1 Then 
              'CAPTCHA validation failed, show error message
              Response.Write "<span class=""incorrect"">Incorrect code</span>"
            Else 
              'CAPTCHA validation passed, perform protected action
              Response.Write "<span class=""correct"">Correct code</span>"
            End If 
          End If
        %>
      </div>
    </fieldset>
    
    <fieldset>
      <legend>ASP Classic CAPTCHA validation</legend>
      <label for="CaptchaCode1">Retype the characters from the picture:</label>
      
      <% 'Adding BotDetect CAPTCHA to the page 
        Dim Captcha2 : Set Captcha2 = (New Captcha)("Captcha2")
        Captcha2.UserInputID = "CaptchaCode2"
        
        Captcha2.CodeLength = 3
        Captcha2.CodeStyleName = "Alpha"
        Captcha2.DisallowedCodeSubstrings = "AAA,BBB,CCC"
        Captcha2.CodeTimeout = 900 '15 minutes
        
        'only re-calcualated on form load
        Dim imageStyleNames(2)
        imageStyleNames(0) = "BlackOverlap"
        imageStyleNames(1) = "Graffiti"
        imageStyleNames(2) = "Overlap"
        Captcha2.ImageStyle = BDC_RandomImageStyleFrom(imageStyleNames)
        
        Captcha2.ImageWidth = 120
        Captcha2.ImageHeight = 35
        
        Captcha2.ImageFormat = BDC_ImageFormats("Png")
        
        Captcha2.CustomDarkColor = "DarkGreen"
        Captcha2.CustomLightColor = "#eeeeff"
        
        Captcha2.SoundStyleName = "Dispatch"
        Captcha2.SoundFormat = BDC_SoundFormats("WavPcm8bit8kHzMono")
        Captcha2.SoundRegenerationMode = BDC_SoundRegenerationModes("None")
        Captcha2.SoundStartDelay = 1000 '1 second
        
        Captcha2.Locale = "fr-CA"
        Captcha2.ImageTooltip = "Custom Canadian French Captcha image tooltip"
        Captcha2.SoundTooltip = "Custom Canadian French Captcha sound icon 
        tooltip"
        Captcha2.ReloadTooltip = "Custom Canadian French Captcha reload icon 
        tooltip"
        Captcha2.HelpLinkUrl = "custom-canadian-french-captcha-help-page.html"
        Captcha2.HelpLinkText = "Custom Canadian French Captcha help link text"
        
        Captcha2.ReloadEnabled = True
        Captcha2.UseSmallIcons = Empty
        Captcha2.UseHorizontalIcons = Empty
        Captcha2.SoundIconUrl = ""
        Captcha2.ReloadIconUrl = ""
        Captcha2.IconsDivWidth = -1
        Captcha2.HelpLinkEnabled = True
        Captcha2.HelpLinkMode = BDC_HelpLinkModes("Image")
        Captcha2.TabIndex = 15
        Captcha2.AdditionalCssClasses = "" 
        Captcha2.AdditionalInlineCss = "" 
        
        Captcha2.AddScriptInclude = False
        Captcha2.AddInitScript = True
        Captcha2.AutoUppercaseInput = False
        Captcha2.AutoFocusInput = False
        Captcha2.AutoClearInput = False
        Captcha2.AutoReloadExpiredCaptchas = True
        Captcha2.AutoReloadTimeout = 3600 '1 hour
        Captcha2.RemoteScriptEnabled = False 
        
        Response.Write Captcha2.Html %>
      
      <div class="validationDiv">
        <input type="text" id="CaptchaCode2" name="CaptchaCode2" />
          
        <% 'CAPTCHA user input validation (only if the form was sumbitted)
          If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
            Dim isHuman2 : isHuman2 = Captcha2.Validate()
            If Not isHuman2 Then 
              'CAPTCHA validation failed, show error message
              Response.Write "<span class=""incorrect"">Incorrect code</span>"
            Else 
              'CAPTCHA validation passed, perform protected action
              Response.Write "<span class=""correct"">Correct code</span>"
            End If 
          End If
        %>
      </div>
    </fieldset>
    
    <input type="submit" name="SubmitButton" id="SubmitButton" value="Submit 
    Form" />
    
  </form>
</body>
</html>

CaptchaConfig.asp

<%

' BotDetect ASP Captcha configuration options
' ---------------------------------------------------------------------------
BotDetect.HelpLinkMode = BDC_HelpLinkModes("Image")

%>

Please Note

The information on this page applies to a discontinued version of BotDetect™ ASP CAPTCHA (v4.x)