2017 © Pedro Peláez

library recaptcha-field

A field for protecting forms against spam in ATK14 applications



A field for protecting forms against spam in ATK14 applications

  • Wednesday, March 28, 2018
  • by yarri
  • Repository
  • 2 Watchers
  • 0 Stars
  • 122 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown



RecaptchaField is a field for protecting forms against spam in ATK14 applications., (*1)

It uses reCAPTCHA v2 from Google (see https://www.google.com/recaptcha/intro/index.html), (*2)


Just use the Composer:, (*3)

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 https://www.google.com/recaptcha/admin#list, (*4)

// file: config/settings.php

// ...

Optionally you can symlink the RecaptchaField files into your project:, (*5)

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:, (*6)

// 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):, (*7)

<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:, (*8)

// 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., (*9)


RecaptchaField is free software distributed under the terms of the MIT license, (*10)

The Versions

28/03 2018


9999999-dev https://github.com/atk14/RecaptchaField

A field for protecting forms against spam in ATK14 applications

  Sources   Download


The Requires

  • php >=5.0.0


url captcha field forms recaptcha atk14

27/03 2018

v0.1 https://github.com/atk14/RecaptchaField

ATK14 form field for protecting forms against spam

  Sources   Download


The Requires

  • php >=5.0.0


url field forms atk14