Using Request Methods
Look at how we can use the request methods to get values using the request object.
We'll cover the following...
Getting values from a submitted form
Let’s say we want to get the values from a submitted form. In the code below, we will create an HTML form to get the product ID and product name from the user. We will then get these values inside a controller.
'use strict' class TestController { //Extracting the view class of the HTTP context add({ view }) { return view.render('add') } product({ request }) { const product_id = request.input('product_id') const product_name = request.input('product_name') return product_id + ', ' + product_name // const form = request.only(['product_id', 'product_name']) // return form.product_id + ', ' + form.product_name } } module.exports = TestController
Press Run and wait for the output to be displayed in the Output tab. You will see a form. Then, click on the link under the Run button, ...