Skip to content

Commit 8d2c0fe

Browse files
authored
docs: Expanded note for CSRF auto-generation (by kenjis explanation) in helpers/form_helper.rst
Expanded note for CSRF auto-generation (by kenjis explanation) in helpers/form_helper.rst
1 parent a503b83 commit 8d2c0fe

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

user_guide_src/source/helpers/form_helper.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ The following functions are available:
112112
<form action="http://example.com/index.php/u/sign-up" method="post" accept-charset="utf-8">
113113
<input type="hidden" id="my-id" name="csrf_test_name" value="964ede6e0ae8a680f7b8eab69136717d">
114114

115-
.. note:: To use auto-generation of CSRF field, you need to enable the :ref:`CSRF filter <enable-csrf-protection>` in **app/Config/Filters.php** file.
115+
.. note:: To use auto-generation of CSRF field, you need to turn on the :ref:`CSRF filter <enable-csrf-protection>` in **app/Config/Filters.php** file.
116+
In most cases the form page is requested using the GET method. Normally, CSRF protection is required
117+
for POST/PUT/DELETE/PATCH requests, but even for GET requests, CSRF filters must be enabled for pages that display Forms.
118+
119+
If you enable CSRF filter with [$globals] https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#globals), it will be active for all request types.
120+
But if you enable CSRF filter with public array $methods = ['POST' => ['csrf']];, the hidden CSRF field will not be added in GET requests.
116121

117122
**Adding Hidden Input Fields**
118123

0 commit comments

Comments
 (0)