diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst index da31f0d9aead..2c49a17c2f0a 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. +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. 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..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') @@ -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'])