Google ReCAPTCHAUser Guide

Google ReCAPTCHA is a support library that aids Fantom-Factory Ltd in the development of other libraries, frameworks and applications. Though you are welcome to use it, you may find features are missing and the documentation incomplete.


Client and Server code to process Google reCAPTCHA responses.

Requires a Google account and reCAPTCHA to be configured on the Admin screen. See:

Quick Start

Client side code:

using afRecaptcha::RecaptchaClient


siteKey     := "..."    // siteKey = your unique Google reCAPTCHA key
enabled     := true     // enabled = false to disable reCAPTCHA during dev
recaptcha   := RecaptchaClient(siteKey, enabled)


containerId := "divId"  // id of where reCAPTCHA is to be rendered
recaptchaId := recaptcha.render(containerId)


response    := recaptcha.getResponse(recaptchaId)
if (response == null)
    Win.cur.alert("If you're a human, complete the captcha!")
    // set a hidden form value to send response to the Server
    doc.elemById("recaptchaInput").setAttr("value", response)

Then when processing form values on the server:

using afIoc::Inject
using afBedSheet::HttpRequest
using afEfanXtra::BeforeRender
using afRecaptcha::RecaptchaServer

@Inject const HttpRequest      httpReq
@Inject const RecaptchaServer  recaptcha

Void onBeforeRender() {
    // inject Google reCAPTCHA scripts into the page

Void onProcessForm() {
    // grab the reCAPTCHA response from the form
    response := httpReq.body.form["recaptchaInput"]

    // verify it with Google
    success  := recaptcha.verifyCaptcha(response, false)
    if (success == false)
        throw Err("reCAPTRUE failed")