diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst index 6443e674d450..6f2c5f997c6e 100644 --- a/user_guide_src/source/tutorial/create_news_items.rst +++ b/user_guide_src/source/tutorial/create_news_items.rst @@ -106,11 +106,22 @@ You're going to do three things here: The code above adds a lot of functionality. +Retrieve the Data +^^^^^^^^^^^^^^^^^ + +First, we use the :doc:`IncomingRequest <../incoming/incomingrequest>` +object ``$this->request``, which is set in the controller by the framework. + +We get the necessary items from the **POST** data by the user and set them in the +``$data`` variable. + Validate the Data ^^^^^^^^^^^^^^^^^ -You'll use the Controller-provided helper function :ref:`validate() ` to validate the submitted data. +Next, you'll use the Controller-provided helper function +:ref:`validateData() ` to validate the submitted data. In this case, the title and body fields are required and in the specific length. + CodeIgniter has a powerful validation library as demonstrated above. You can read more about the :doc:`Validation library <../libraries/validation>`. diff --git a/user_guide_src/source/tutorial/create_news_items/005.php b/user_guide_src/source/tutorial/create_news_items/005.php index 6d565789141a..bf3a3e2b3bb0 100644 --- a/user_guide_src/source/tutorial/create_news_items/005.php +++ b/user_guide_src/source/tutorial/create_news_items/005.php @@ -13,8 +13,10 @@ public function create() { helper('form'); + $data = $this->request->getPost(['title', 'body']); + // Checks whether the submitted data passed the validation rules. - if (! $this->validate([ + if (! $this->validateData($data, [ 'title' => 'required|max_length[255]|min_length[3]', 'body' => 'required|max_length[5000]|min_length[10]', ])) {