Welcome Guest, Not a member yet? Register   Sign In
array $ _POST always empty

(This post was last modified: 07-13-2022, 02:44 PM by includebeer. Edit Reason: link to image was not working )

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


(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?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/

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

(This post was last modified: 07-13-2022, 09:20 PM by iRedds.)

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).

Theme © iAndrew 2016 - Forum software by © MyBB