Skip to content

Commit c0fedce

Browse files
committed
docs: add CSRF error display in sample code
1 parent 73371c4 commit c0fedce

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

user_guide_src/source/tutorial/create_news_items.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ the slug from our title in the model. Create a new view at
3333

3434
<h2><?= esc($title) ?></h2>
3535

36+
<?= session()->getFlashdata('error') ?>
3637
<?= service('validation')->listErrors() ?>
3738

3839
<form action="/news/create" method="post">
@@ -47,10 +48,15 @@ the slug from our title in the model. Create a new view at
4748
<input type="submit" name="submit" value="Create news item" />
4849
</form>
4950

50-
There are probably only two things here that look unfamiliar. The
51-
``service('validation')->listErrors()`` function is used to report
52-
errors related to form validation. The ``csrf_field()`` function creates
53-
a hidden input with a CSRF token that helps protect against some common attacks.
51+
There are probably only three things here that look unfamiliar.
52+
53+
The ``<?= session()->getFlashdata('error') ?>`` function is used to report
54+
errors related to CSRF protection.
55+
56+
The ``service('validation')->listErrors()`` function is used to report
57+
errors related to form validation.
58+
59+
The ``csrf_field()`` function creates a hidden input with a CSRF token that helps protect against some common attacks.
5460

5561
Go back to your ``News`` controller. You're going to do two things here,
5662
check whether the form was submitted and whether the submitted data

0 commit comments

Comments
 (0)