Skip to content

Commit a4df106

Browse files
authored
docs: Fix some typos and expand csrf auto-generation explanation (by Kenjis) helpers/form_helper.rst
Fix some typos and expand csrf auto-generation explanation (by Kenjis) helpers/form_helper.rst
1 parent 579a473 commit a4df106

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

user_guide_src/source/helpers/form_helper.rst

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Escaping Field Values
2828
*********************
2929

3030
You may need to use HTML and characters such as quotes within your form
31-
elements. In order to do that safely, you'll need to use
31+
elements. In order to do that safely, you'll need to use the
3232
:doc:`common function <../general/common_functions>`
3333
:php:func:`esc()`.
3434

@@ -64,8 +64,8 @@ The following functions are available:
6464

6565
Creates an opening form tag with a site URL **built from your** ``Config\App::$baseURL``.
6666
It will optionally let you add form attributes and hidden input fields, and
67-
will always add the `accept-charset` attribute based on the charset value in your
68-
config file.
67+
will always add the `accept-charset` attribute based on the ``$charset`` property in your
68+
**app/Config/App.php** config file.
6969

7070
The main benefit of using this tag rather than hard coding your own HTML is that
7171
it permits your site to be more portable in the event your URLs ever change.
@@ -103,16 +103,21 @@ The following functions are available:
103103

104104
<form action="http://example.com/index.php/email/send" class="email" id="myform" method="post" accept-charset="utf-8">
105105

106-
If :ref:`CSRF <cross-site-request-forgery>` filter is turned on ``form_open()`` will generate CSRF field at the beginning of the form. You can specify ID of this field by passing csrf_id as one of the ``$attribute`` array:
106+
If :ref:`CSRF <cross-site-request-forgery>` filter is turned on ``form_open()`` will generate CSRF field at the beginning of the form. You can specify ID of this field by passing **csrf_id** as an element of the ``$attributes`` array:
107107

108108
.. literalinclude:: form_helper/007.php
109109

110110
will return::
111111

112112
<form action="http://example.com/index.php/u/sign-up" method="post" accept-charset="utf-8">
113-
<input type="hidden" id="my-id" name="csrf_field" value="964ede6e0ae8a680f7b8eab69136717d">
113+
<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 turn CSRF filter on to the form page. In most cases it is requested using the ``GET`` method.
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

@@ -278,7 +283,7 @@ The following functions are available:
278283
:param array $options: An associative array of options to be listed
279284
:param array $selected: List of fields to mark with the *selected* attribute
280285
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
281-
:returns: An HTML multiselect (dropdown) element
286+
:returns: An HTML select element with multiple attribute
282287
:rtype: string
283288

284289
Lets you create a standard multiselect field. The first parameter will
@@ -403,7 +408,7 @@ The following functions are available:
403408
:param string $data: Button name
404409
:param string $value: Button value
405410
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
406-
:returns: An HTML input reset button element
411+
:returns: An HTML input reset element
407412
:rtype: string
408413

409414
Lets you generate a standard reset button. Use is identical to
@@ -452,10 +457,10 @@ The following functions are available:
452457
:returns: Field value
453458
:rtype: string
454459

455-
Permits you to set the value of an input form or textarea. You must
460+
Permits you to set the value of an input or textarea element. You must
456461
supply the field name via the first parameter of the function. The
457462
second (optional) parameter allows you to set a default value for the
458-
form. The third (optional) parameter allows you to turn off HTML escaping
463+
field value. The third (optional) parameter allows you to turn off HTML escaping
459464
of the value, in case you need to use this function in combination with
460465
i.e., :php:func:`form_input()` and avoid double-escaping.
461466

0 commit comments

Comments
 (0)