Welcome Guest, Not a member yet? Register   Sign In
Cannot access request values from controller
#4

(This post was last modified: 01-30-2023, 08:30 AM by ikesela.)

Your need to set 3 part:

Routes (App\Config\Routes.php) :
wil be like this: http:yourdomain.com/ajax

$routes->get('ajax', 'Home::viewForm', ['as' => 'ajaxform']); // to view form , need create function viewForm in controller (this example) , route with name
$routes->post('ajax', 'Home::ajaxTest');

Your FORM: (app\Views\ your_view_file_names.php):
<form action="<?=route_to('ajaxform')?>" method="POST">

Your Controller Home.php (App\Controller):
public function viewForm()
{
return view('App\Views\your_view_file_names' , [ 'data' => $your_data_to_show_in_view ]);
}

public function ajaxTest()
{
$fname= $this->request->getPost('fname');
$lname = $this->request->getPost('lname');

$allPost = $this->request->getPost(); // get all value

return redirect()->back();
}
Reply


Messages In This Thread
RE: Cannot access request values from controller - by ikesela - 01-30-2023, 08:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB