setCsrfTokenValue

setCsrfTokenValue(string $tokenValue)

Specify the token value for CSRF protection. This value will only be sent through AJAX calls if it is not empty.

Codeigniter version 4 example

Step 1. Go to app/Config/Filters.php and uncomment the 'csrf' string at $globals For example:

// Always applied before every request
public $globals = [
    'before' => [
        //'honeypot'
        'csrf',
    ],
    'after'  => [
        'toolbar',
        //'honeypot'
    ],
];

Step 2. Add the functions setCsrfTokenName and setCsrfTokenName:

$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
$crud->columns(['customerName','phone','addressLine1','creditLimit']);

$crud->setCsrfTokenName(csrf_token());
$crud->setCsrfTokenValue(csrf_hash());

$output = $crud->render();

and that's it really!

Codeigniter version 3 example

Step 1. Go to application/config/config.php and change the csrf_protection to be equal with TRUE. More specifically:

$config['csrf_protection'] = TRUE;

Step 2. Add the functions setCsrfTokenName and setCsrfTokenName:

$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
$crud->columns(['customerName','phone','addressLine1','creditLimit']);

$crud->setCsrfTokenName($this->security->get_csrf_token_name());
$crud->setCsrfTokenValue($this->security->get_csrf_hash());

$output = $crud->render();