I want to do something when csrf validation failed in controller,
I am having a hard time figuring this out,
Check out the code below,
View => csrf.php,
<?= session()->getFlashdata('error') ?>
<form method="post" action="<?=base_url('/test_csrf')?>">
<?= csrf_field() ?>
<label for="name">Name:</label>
<input type="text" name="name" id="name">
<br>
<label for="email">Email:</label>
<input type="email" name="email" id="email">
<br>
<button type="submit">Submit</button>
</form>
Controller => Welcome.php,
<?php
namespace AppControllers;
use CodeIgniterSecurityExceptionsSecurityException;
class Welcome extends BaseController
{
public function __construct()
{
// $this->middleware('MyFilter');
}
public function index()
{
echo 'Hello, this is your first controller in CodeIgniter 4!';
}
public function csrf(){
return view('csrf');
}
public function test_csrf(){
// do something when csrf failed here.
}
}