how to get input text param from view in the controller (cakephp)

370 Views Asked by At

When I type a text in the input and click save changes I want to get the value in the controller.

<form action="/lms/dashboard/index" method="post" enctype="multipart/form-data">
<input id='name' name='name' type="text">
<button type="submit"  id="btnSubmit" value="submit" >Save Changes</button>

public function index() {
    $hasvalue = $this->_params['name'];
        if(!empty($hasvalue))
           {
            pr(' param found');
           }
           }
2

There are 2 best solutions below

0
On

You can access your form data in your controller action by calling the following method:

Array $inputData = $this->request->getData();

You can see more details about handling request and response in CakePHP here: https://book.cakephp.org/3.0/en/controllers/request-response.html#

0
On

You can get all the form data using

$hasvalue = $this->request->data();    //CakePHP 3.0
$hasvalue = $this->request->getData();    //CakePHP 3.4