(09-27-2020, 03:01 AM)nc03061981 Wrote: Now you post one more:
1. Your Routes
2. Your Controller Test
3. Your View
and then, every one will help you
My file now:
Routes.php:
PHP Code:
<?php namespace Config;
// Create a new instance of our RouteCollection class.
$routes = Services::routes();
// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (file_exists(SYSTEMPATH . 'Config/Routes.php'))
{
require SYSTEMPATH . 'Config/Routes.php';
}
/**
* --------------------------------------------------------------------
* Router Setup
* --------------------------------------------------------------------
*/
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);
/**
* --------------------------------------------------------------------
* Route Definitions
* --------------------------------------------------------------------
*/
// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');
$routes->get('test', 'Test::index', ['as' => 'test']);
$routes->post('test/send', 'Test::send');
//$routes->post('test/send', 'App\Test::send');
/**
* --------------------------------------------------------------------
* Additional Routing
* --------------------------------------------------------------------
*
* There will often be times that you need additional routing and you
* need it to be able to override any defaults in this file. Environment
* based routes is one such time. require() additional route files here
* to make that happen.
*
* You will have access to the $routes object within that file without
* needing to reload it.
*/
if (file_exists(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'))
{
require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}
My controller Test.php:
PHP Code:
<?php
namespace App\Controllers;
class Test extends BaseController
{
// available to GET requests only
public function index()
{
return view('test_2');
}
// available to POST requests only
public function send()
{
$data = [
'name' => $this->request->getPost('name'),
'lastname' => $this->request->getPost('lastname'),
];
$data['namepost'] = $this->request->getPost('name');
$data['testing'] = 'datiinarrivo';
return view('test_1', $data);
}
}
View test_1.php
PHP Code:
Test 1 si post
Nome: <?= $name; ?><br/>
Cognome: <?= $lastname; ?><br/>
Test: <?= $testing; ?><br/>
View test_2.php:
PHP Code:
Test 2 nessun post
<form action="test/send" method="post">
<input type="text" name="name" value="Mario" id="name">
<input type="text" name="lastname" value="Rossi" id="lastname">
<input type="submit" name="submit" value="submit" id="submit">
</form>
The output html:
Code:
Test 1 si post Nome:
Cognome:
Test: datiinarrivo
The header with inspector at 192.168.10.200/test/send:
Code:
General:
Request URL: http://192.168.10.200/test/send
Request Method: POST
Status Code: 200 OK
Remote Address: 192.168.10.200:80
Referrer Policy: no-referrer-when-downgrade
Response header:
Cache-control: no-store, max-age=0, no-cache
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 76
Content-Type: text/html; charset=UTF-8
Date: Sun, 27 Sep 2020 12:37:34 GMT
Keep-Alive: timeout=5, max=93
Server: Apache/2.4.43 (Debian)
Vary: Accept-Encoding
Request header:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 39
Content-Type: application/x-www-form-urlencoded
Host: 192.168.10.200
Origin: http://192.168.10.200
Referer: http://192.168.10.200/test
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
Form Data:
name: Mario
lastname: Rossi
submit: submit
From the inspector, the method seems POST and the form data present......
Mahhh.......