Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter $this->input->post() empty while $_POST is working correctly

Tags:

On a codeigniter installation, I am trying to use the inbuilt $this->input->post('some_data') function, however $this->input->post() is an empty array.

A print_r($_POST) gives all the variables fully and correctly?

According to the codeigniter docs, The input class "is initialized automatically by the system so there is no need to do it manually", leaving me wondering what else I'm meant to do.

Any thoughts on how I should try to get this working?

Thanks!

like image 298
Matthew Higgins Avatar asked Sep 11 '12 19:09

Matthew Higgins


1 Answers

You can check, if your view looks something like this (correct):

<form method="post" action="/controller/submit/">

vs (doesn't work):

<form method="post" action="/controller/submit">

Second one here is incorrect, because it redirects without carrying over post variables.

Explanation:

When url doesn't have slash in the end, it means that this points to a file.

Now, when web server looks up the file, it sees, that this is really a directory and sends a redirect to the browser with a slash in the end.

Browser makes new query to the new URL with slash, but doesn't post the form contents. That's where the form contents are lost.

like image 149
Rauli Rajande Avatar answered Sep 19 '22 15:09

Rauli Rajande