Hi guys..
I started a new project with ci4 (my first time with 4), and I have a problem that seems really stupid: I can't pass POST data between the view and the controller. I've done a lot of test, but I don't understand where the problem lies.
The controller Test.php:
Code:
<?php namespace App\Controllers;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\Response;
class Test extends BaseController
{
public function index()
{
$response = service('response');
$request = service('request');
echo $request->uri->getPath()."<br>";
echo $request->getMethod()."<br>";
if ($request->getVar('submit'))
{
if (isset($_POST['name']))
{
echo "Nome: ".$_POST['name']."<br>";
}
if (isset($_POST['lastname']))
{
echo "Cognome: ".$_POST['lastname'];
}
return view('test_1');
} else
{
return view('test_2');
}
}
//--------------------------------------------------------------------
}
view test_1.php:
view test_2.php
Code:
Test 2 nessun post
<form action="test" 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>
When i try to submit the form, in the response, i haven't any POST data and reopen test_2 view. This is the html source code:
Code:
test<br>get<br><!-- DEBUG-VIEW START 1 APPPATH/Config/../Views/test_2.php -->
Test 2 nessun post
<form action="test" 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>
<!-- DEBUG-VIEW ENDED 1 APPPATH/Config/../Views/test_2.php -->
<script type="text/javascript" id="debugbar_loader" data-time="1600851974" src="[url=http://www.yiisupertest.com/?debugbar]http://www.yiisupertest.com/?debugbar[/url]"></script><script type="text/javascript" id="debugbar_dynamic_script"></script><style type="text/css" id="debugbar_dynamic_style"></style>
I don't understand where i s the problem....
If i try without codeigniter, with only php simple file, the post data works fine. I followed this guide:https://guidaphp.it/base/variabili-superglobali and post data work.
I don't know how to do it anymore
any help is welcome