Skip to content

Google reCAPTCHA V2 Server-Side and Client-Side Validation with Plain PHP and Vanilla JS

License

Notifications You must be signed in to change notification settings

Tes3awy/recaptcha-vanilla-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YouTube Views Top Lang Forks Stars Issues Pre-Commit License

Google reCAPTCHA V2 Checkbox Server-Side and Client-Side Validation

GIF

The repo includes a complete sample code of how server-side & client-side Google reCATPCHA V2 validations work.

Table of Contents

  1. Installation
  2. Data Attributes
  3. YouTube Tutorials
    1. Server Side Validation
    2. Client Side Validation

Installation

$ git clone https://github.com/Tes3awy/recaptcha-vanilla-php.git
$ cd recaptcha-vanilla-php
$ code . # Only if you are using VSCode

To begin with, you MUST provide both sitekey and secretkey in environment.php file. These keys are provided when you create a reCAPTCHA V2 Checkbox.

It's a best practice approach to add those keys in environment variables as no one should have access to your secretkey.

Data Attributes

data-sitekey="<SITE_KEY>" (Required)
data-theme="<THEME>" (Optional. Allowed values: "light" or "dark". Default: `light`)
data-size="<SIZE>" (Optional. Allowed values: "normal" or "compact". Default: `normal`)
data-callback="<CALLBACK_FUNCTION>" (Optional)
data-expired-callback="<EXPIRY_CALLBACK_FUNCTION>" (Optional)
data-error-callback="<ERROR_CALLBACK_FUNCTION>" (Optional)

I used Bootstrap v5.2.3 as the front-end library. And the zephyr.min.css was downloaded from Bootswatch (Zephyr Theme)


YouTube Tutorials

Server Side Validation

I made a tutorial about the server-side validation on YouTube. Grab your cup of coffee and enjoy 😉

Server Side Validation


Client Side Validation

You can also watch the client-side validation tutorial on YouTube

Client Side Validation


For reference, please visit Google reCAPTCHA Developers Guide.