Docs Backend Validation

Backend Validation

After form submission, your server receives captcha_token and captcha_solution. Forward both to /verify, check that success === true, and reject the request if verification fails.

The widget appends two hidden fields to your form on submit — captcha_token and captcha_solution. Never trust client-side verification; always call /verify server-side.

This step is required for security. Skipping backend verification leaves your form effectively unprotected.

PHP

Laravel

Recommended

Use the built-in HTTP client. Drop this into your form handler.

php
use Illuminate\Support\Facades\Http;

$response = Http::timeout(3)->post('https://captchaapi.eu/api/v1/captcha/verify', [
    'token'    => $request->input('captcha_token'),
    'solution' => $request->input('captcha_solution'),
]);

if ($response->failed() || ! $response->json('success')) {
    return back()->withErrors([
        'captcha' => 'Captcha verification failed.',
    ]);
}
PHP

Plain PHP

Basic example

No dependencies required.

php
$response = file_get_contents('https://captchaapi.eu/api/v1/captcha/verify', false, stream_context_create([
    'http' => [
        'method'  => 'POST',
        'header'  => "Content-Type: application/json",
        'content' => json_encode([
            'token'    => $_POST['captcha_token'],
            'solution' => $_POST['captcha_solution'],
        ]),
    ],
]));

$data = json_decode($response, true);

if (! $data['success']) {
    die('Captcha failed');
}
JavaScript

Node.js / Express

Basic example

Using axios. Works with any Node framework.

js
const axios = require('axios');

app.post('/form', async (req, res) => {
    const response = await axios.post('https://captchaapi.eu/api/v1/captcha/verify', {
        token: req.body.captcha_token,
        solution: req.body.captcha_solution,
    });

    if (!response.data.success) {
        return res.status(400).send('Captcha failed');
    }

    return res.send('OK');
});
Python

Python / Flask

Basic example

Using the requests library.

python
import requests

response = requests.post('https://captchaapi.eu/api/v1/captcha/verify', json={
    'token':    request.form.get('captcha_token'),
    'solution': request.form.get('captcha_solution'),
})

data = response.json()

if not data['success']:
    return 'Captcha failed', 400
Go

Go / net/http

Basic example

Standard library only — no dependencies.

go
resp, err := http.Post("https://captchaapi.eu/api/v1/captcha/verify", "application/json",
    bytes.NewBuffer([]byte(`{
        "token": "`+r.FormValue("captcha_token")+`",
        "solution": "`+r.FormValue("captcha_solution")+`"
    }`)),
)
if err != nil {
    http.Error(w, "Captcha failed", 400)
    return
}
defer resp.Body.Close()

var data map[string]interface{}
json.NewDecoder(resp.Body).Decode(&data)

if data["success"] != true {
    http.Error(w, "Captcha failed", 400)
    return
}

Related