[SOLVED] - Strange problem with POST data |
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; view test_1.php: Code: Test1 si post view test_2.php Code: Test 2 nessun post 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 --> 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
You can process POST with:
$request = \Config\Services::request(); $name = $request->getPost('name'); $lastname = $request->getPost('lastname'); Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams (09-23-2020, 02:23 AM)nc03061981 Wrote: You can process POST with: I tryed but don't work: Test.php: Code: <?php namespace App\Controllers; Output: Code: test<br>get<br>StarttestingNameEndtestingName<br><!-- DEBUG-VIEW START 1 APPPATH/Config/../Views/test_2.php --> as you can see in the output, the variable "name" is empty, and there is nothing between the two strings testingname..... I'm going crazy.....
error Logic
First var_dump($_POST); die(); to see your post info No need 2 lines: use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Response; Only use: $request = \Config\Services::request(); and Form action, you should leave empty to post to current Controller <form action="test" method="post"> to <form action="" method="post"> Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams (09-23-2020, 02:49 AM)nc03061981 Wrote: error Logic I added a new public function in controller with name "return" where i put var_dump($_POST); and die(); I change the action in form to test/return. the response: Code: array(0) { } I have never had all these problem in my php experience....... For information, i testing my apache and php with this simple index.php file: Code: <?php The output, after submit is: Code: Nome: Mario<br>Cognome: Rossi The post data work fine OUTSIDE Codeigniter....... Is there a limitation? I there a flag that i don't know? this is my .env file, if necessary (i'm in development environmental): Code: #--------------------------------------------------------------------
You should leave form action=''
- because your data do not post to right Controller, so you will not see post data Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams
Var_dump in your controller
1. Comment // var_dump($_POST) // die(); save file and refresh browser 2. Uncomment var_dump($_POST) die(); Save file and press Sumbit button Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams
Never tried it this way but why is the post action just the name of the function ? and not the url to the function like :
action="<?php echo base_url('ControllerName/function'); ?>" then in your controller $request = \Config\Services::request(); $name = $request->getVar('name'); $lastname = $request->getVar('lastname'); |
Welcome Guest, Not a member yet? Register Sign In |