Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

jbennecker/silverstripe-recaptcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recaptcha FormField Module

Introduction

This module adds a RecaptchaField to SilverStripe 4.x, which you can use in custom forms.

Install

composer require jbennecker/silverstripe-recaptcha

Usage

Put your keys in app/_config/app.yml

jbennecker\recaptcha\Forms\RecaptchaField:
  public_api_key: "public key"
  private_api_key: "private key"

Then you can use the Field in your forms.

    public function HelloForm()
    {
        $fields = new FieldList(
            TextField::create('Name', _t('HelloForm.Name', 'Name')),
            TextField::create('Email', _t('HelloForm.Email', 'E-Mail')),
            TextareaField::create('Nachricht', _t('HelloForm.Nachricht', 'Nachricht')),
            RecaptchaField::create('recaptcha') // <--- add this
        );

        $actions = new FieldList(
            FormAction::create('doSayHello')->setTitle(_t('HelloForm.Submit', 'Senden'))
        );

        $required = new RequiredFields('Name', 'Email', 'Nachricht');

        $form = new Form($this, 'HelloForm', $fields, $actions, $required);

        return $form;
    }