PHP code example of davodm / codeigniter4-turnstile

1. Go to this page and download the library: Download davodm/codeigniter4-turnstile library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

davodm / codeigniter4-turnstile example snippets


helper('turnstile');
echo turnstile_implicit('turnstile_field_name', 'auto', 'normal');

helper('turnstile');
turnstile_explicit('turnstile_field_name', 'dark', 'normal');

<div id="turnstile_field_name"></div>

<?= turnstile_explicit_render(); 

public $ruleSets = [
    // other rules
    \CI4CFTurnstile\Validation\TurnstileRules::class,
];

$validation = \Config\Services::validation();

$validation->setRules([
    'turnstile_field_name' => 'ors = $validation->getErrors();
    // Display errors to the user
}

namespace App\Controllers;

use CodeIgniter\Controller;

class FormController extends Controller
{
    public function index()
    {
        helper('turnstile');
        return view('form');
    }

    public function submit()
    {
        $validation = \Config\Services::validation();

        $validation->setRules([
            'turnstile_field_name' => '

<!-- Implicit form model -->
<form method="post" action="/form/submit">
    <!-- Other form fields -->
    <?= turnstile_implicit('turnstile_field_name');