CodeIgniter Forums
array $ _POST always empty - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: array $ _POST always empty (/showthread.php?tid=82445)



array $ _POST always empty - enrico.carli - 07-11-2022

Good evening everyone,



i am new to codeigniter 4, i used 3.



I'm making a simple form with method = post



which refers to a controller;



I followed the tutorial on the guide of ci4 "build your first app"



however the array I get $ _POST is always empty.



i think there is an htaccess rule that adds a trailing slash,



doing so I lose the array.



Has it already happened to anyone?



Thanks a lot to those who will help me



sorry my english


https://drive.google.com/file/d/14xmLu4fpDISSheJ9HUeIvninqoY3FWRe/view?usp=sharing


RE: array $ _POST always empty - includebeer - 07-13-2022

(07-11-2022, 12:33 PM)enrico.carli Wrote: i think there is an htaccess rule that adds a trailing slash,

There's no such rule in the .htaccess provided with the framework. Did you add rules to the file?


RE: array $ _POST always empty - kenjis - 07-13-2022

Your rule redirects the POST request, and you will see the next GET request. So $_POST is empty, because it is a GET request.


RE: array $ _POST always empty - iRedds - 07-13-2022

Yes, there is a slash rule in .htaccess. Only it does not add, but removes the slash. You can even see it in your screenshot.

Three solutions.
1. Remove slash from url (recommended)
2. Remove forward slash rule
3. Change the response code in the slash redirect rule from 301 to 308 (or 307).