A field for protecting forms against spam in ATK14 applications

v0.1.2 2019-12-04 11:34 UTC

This package is auto-updated.

Last update: 2021-05-04 14:36:07 UTC


RecaptchaField is a field for protecting forms against spam in ATK14 applications.

It uses reCAPTCHA v2 from Google (see


Just use the Composer:

cd path/to/your/atk14/project/
composer require atk14/recaptcha-field

You must define two constants in config/settings.php. Get their right values at

// file: config/settings.php

// ...

Optionally you can symlink the RecaptchaField files into your project:

ln -s ../../vendor/atk14/recaptcha-field/src/app/fields/recaptcha_field.php app/fields/recaptcha_field.php
ln -s ../../vendor/atk14/recaptcha-field/src/app/widgets/recaptcha_widget.php app/widgets/recaptcha_widget.php

Usage in a ATK14 application

In a form:

// file: app/forms/users/create_new_form.php
class CreateNewForm extends ApplicationForm {

  function set_up(){
    $this->add_field("firstname", new CharField([
      "label" => "Firstname",
      "max_length" => 200,

    $this->add_field("lastname", new CharField([
      "label" => "Lastname",
      "max_length" => 200,

    // other fields

    $this->add_field("captcha",new RecaptchaField([
      "label" => "Spam protection"

  function clean(){
    list($err,$values) = parent::clean();

    // perhaps you may not want to have "captcha" in the cleaned data
    if(is_array($values)){ unset($values["captcha"]); }

    return [$err,$values];

In a template (a shared template from the Atk14Skelet is used):

<h1>User Registration</h1>


    {render partial="shared/form_field" fields="firstname,lastname,..."}

    {render partial="shared/form_field" fields="captcha"}

  <button type="submit">Register</button>


In a controller:

// file: app/controllers/users_controller.php
class UsersController extends ApplicationController {
  function create_new(){
    if($this->request->post() && ($values = $this->form->validate($this->params))){
      // There's no need to care about the $values["captcha"] since it was unset in CreateNewForm::clean()
      $this->flash->success("Your registration has been successfully performed");

Example of usage

The RecaptchaField is used in the registration form on ATK14 Forum for instance.


RecaptchaField is free software distributed under the terms of the MIT license