Skip to content

Commit 0ce62d9

Browse files
authored
Merge pull request #8935 from obozdag/patch-12
docs: fix helpers/form_helper.rst
2 parents 5c065ed + 2850b22 commit 0ce62d9

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

user_guide_src/source/helpers/form_helper.rst

Lines changed: 26 additions & 21 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 :ref:`filters-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

@@ -145,7 +150,7 @@ The following functions are available:
145150
146151
:param string $name: Field name
147152
:param string $value: Field value
148-
:returns: An HTML hidden input field tag
153+
:returns: An HTML hidden input element
149154
:rtype: string
150155

151156
Lets you generate hidden input fields. You can either submit a
@@ -171,7 +176,7 @@ The following functions are available:
171176
:param string $value: Field value
172177
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
173178
:param string $type: The type of input field. i.e., 'text', 'email', 'number', etc.
174-
:returns: An HTML text input field tag
179+
:returns: An HTML text input element
175180
:rtype: string
176181

177182
Lets you generate a standard text input field. You can minimally pass
@@ -206,7 +211,7 @@ The following functions are available:
206211
:param array $data: Field attributes data
207212
:param string $value: Field value
208213
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
209-
:returns: An HTML password input field tag
214+
:returns: An HTML password input element
210215
:rtype: string
211216

212217
This function is identical in all respects to the :php:func:`form_input()`
@@ -217,7 +222,7 @@ The following functions are available:
217222
:param array $data: Field attributes data
218223
:param string $value: Field value
219224
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
220-
:returns: An HTML file upload input field tag
225+
:returns: An HTML file upload input element
221226
:rtype: string
222227

223228
This function is identical in all respects to the :php:func:`form_input()`
@@ -229,7 +234,7 @@ The following functions are available:
229234
:param array $data: Field attributes data
230235
:param string $value: Field value
231236
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
232-
:returns: An HTML textarea tag
237+
:returns: An HTML textarea element
233238
:rtype: string
234239

235240
This function is identical in all respects to the :php:func:`form_input()`
@@ -244,7 +249,7 @@ The following functions are available:
244249
:param array $options: An associative array of options to be listed
245250
:param array $selected: List of fields to mark with the *selected* attribute
246251
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
247-
:returns: An HTML dropdown select field tag
252+
:returns: An HTML select (dropdown) element
248253
:rtype: string
249254

250255
Lets you create a standard drop-down field. The first parameter will
@@ -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 dropdown multiselect field tag
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
@@ -326,7 +331,7 @@ The following functions are available:
326331
:param string $value: Field value
327332
:param bool $checked: Whether to mark the checkbox as being *checked*
328333
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
329-
:returns: An HTML checkbox input tag
334+
:returns: An HTML checkbox input element
330335
:rtype: string
331336

332337
Lets you generate a checkbox field. Simple example:
@@ -357,7 +362,7 @@ The following functions are available:
357362
:param string $value: Field value
358363
:param bool $checked: Whether to mark the radio button as being *checked*
359364
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
360-
:returns: An HTML radio input tag
365+
:returns: An HTML radio input element
361366
:rtype: string
362367

363368
This function is identical in all respects to the :php:func:`form_checkbox()`
@@ -368,7 +373,7 @@ The following functions are available:
368373
:param string $label_text: Text to put in the <label> tag
369374
:param string $id: ID of the form element that we're making a label for
370375
:param string $attributes: HTML attributes
371-
:returns: An HTML field label tag
376+
:returns: An HTML label element
372377
:rtype: string
373378

374379
Lets you generate a <label>. Simple example:
@@ -387,7 +392,7 @@ The following functions are available:
387392
:param string $data: Button name
388393
:param string $value: Button value
389394
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
390-
:returns: An HTML input submit tag
395+
:returns: An HTML input submit element
391396
:rtype: string
392397

393398
Lets you generate a standard submit button. Simple example:
@@ -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 tag
411+
:returns: An HTML input reset element
407412
:rtype: string
408413

409414
Lets you generate a standard reset button. Use is identical to
@@ -414,7 +419,7 @@ The following functions are available:
414419
:param string $data: Button name
415420
:param string $content: Button label
416421
:param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string
417-
:returns: An HTML button tag
422+
:returns: An HTML button element
418423
:rtype: string
419424

420425
Lets you generate a standard button element. You can minimally pass the
@@ -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

user_guide_src/source/incoming/filters.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Filters can be specified by adding their alias to either the ``before`` or ``aft
139139

140140
.. literalinclude:: filters/013.php
141141

142+
.. _filters-globals:
143+
142144
$globals
143145
--------
144146

user_guide_src/source/libraries/security.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ This provides a nicer experience than simply crashing.
152152

153153
Even when the redirect value is ``true``, AJAX calls will not redirect, but will throw a SecurityException.
154154

155+
.. _enable-csrf-protection:
156+
155157
Enable CSRF Protection
156158
======================
157159

0 commit comments

Comments
 (0)