use Drupal\Core\Controller\ControllerBase; class MyController extends ControllerBase { public function handleRequest() { $request = \Drupal::request(); if ($request->getMethod() == 'GET') { $name = $request->query->get('name'); $age = $request->query->get('age'); // Do something with the name and age parameters } } }
use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Controller\ControllerBase; class MyController extends ControllerBase { public function handleRequest() { $request = \Drupal::request(); if ($request->getMethod() == 'POST') { $name = $request->request->get('name'); $age = $request->request->get('age'); // Do something with the name and age parameters, such as saving to database $response = new AjaxResponse(); $response->addCommand( new \Drupal\Core\Ajax\RedirectCommand('/thank-you') ); return $response; } } }In this example, the `getRequest()` function is used to get the current request object, which is then used to check if the method is `POST` and to retrieve any form parameters such as `name` and `age`. The example also includes an Ajax response that redirects the user to a thank-you page after the form is submitted. The Drupal request module is included in the Drupal Core package library.