From 5c6725576875203c4b140b30344cad78615fabe8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 25 Dec 2022 08:34:39 +0900 Subject: [PATCH 1/4] docs: we should check max length first --- user_guide_src/source/tutorial/create_news_items/002.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/tutorial/create_news_items/002.php b/user_guide_src/source/tutorial/create_news_items/002.php index 2a5de8ff91a9..e2dc7461ef5d 100644 --- a/user_guide_src/source/tutorial/create_news_items/002.php +++ b/user_guide_src/source/tutorial/create_news_items/002.php @@ -24,8 +24,8 @@ public function create() // Checks whether the submitted data passed the validation rules. if (! $this->validateData($post, [ - 'title' => 'required|min_length[3]|max_length[255]', - 'body' => 'required|min_length[10]|max_length[5000]', + 'title' => 'required|max_length[255]|min_length[3]', + 'body' => 'required|max_length[5000]|min_length[10]', ])) { // The validation fails, so returns the form. return view('templates/header', ['title' => 'Create a news item']) From 78fb53bfe0a2fdc5d1b2193377af0852fd47227f Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 25 Dec 2022 08:36:28 +0900 Subject: [PATCH 2/4] docs: use $this->request->is() --- user_guide_src/source/tutorial/create_news_items/002.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/tutorial/create_news_items/002.php b/user_guide_src/source/tutorial/create_news_items/002.php index e2dc7461ef5d..be1ad6a54836 100644 --- a/user_guide_src/source/tutorial/create_news_items/002.php +++ b/user_guide_src/source/tutorial/create_news_items/002.php @@ -13,7 +13,7 @@ public function create() helper('form'); // Checks whether the form is submitted. - if (strtolower($this->request->getMethod()) !== 'post') { + if (! $this->request->is('post')) { // The form is not submitted, so returns the form. return view('templates/header', ['title' => 'Create a news item']) . view('news/create') From bcfd7542250c227d015cadc52ab9f377f6056289 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 25 Dec 2022 08:44:06 +0900 Subject: [PATCH 3/4] docs: update the explanation --- user_guide_src/source/tutorial/create_news_items.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst index da31f0d9aead..b34418668289 100644 --- a/user_guide_src/source/tutorial/create_news_items.rst +++ b/user_guide_src/source/tutorial/create_news_items.rst @@ -90,7 +90,8 @@ Most helper functions require the helper to be loaded before use. Next, we check if we deal with the **POST** request with the :doc:`IncomingRequest <../incoming/incomingrequest>` object ``$this->request``. It is set in the controller by the framework. -If the HTTP method is not POST, that is it is GET, +The :ref:`IncomingRequest::is() ` method checks the type of the request. +If the request is not a POST request, that is it is a GET request, the form is loaded and returned to display. Then, we get the necessary items from the POST data by the user and set them in the ``$post`` variable. From 07af7a4df982f8d3b5eeada95171aac735f38d1b Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 26 Dec 2022 17:46:09 +0900 Subject: [PATCH 4/4] docs: improve explanation Co-authored-by: Michal Sniatala --- user_guide_src/source/tutorial/create_news_items.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst index b34418668289..2c49a17c2f0a 100644 --- a/user_guide_src/source/tutorial/create_news_items.rst +++ b/user_guide_src/source/tutorial/create_news_items.rst @@ -91,7 +91,7 @@ Next, we check if we deal with the **POST** request with the :doc:`IncomingRequest <../incoming/incomingrequest>` object ``$this->request``. It is set in the controller by the framework. The :ref:`IncomingRequest::is() ` method checks the type of the request. -If the request is not a POST request, that is it is a GET request, +Since the route for **create()** endpoint handles both: **GET** and **POST** requests we can safely assume that if the request is not POST then it is a GET type. the form is loaded and returned to display. Then, we get the necessary items from the POST data by the user and set them in the ``$post`` variable.