Welcome Guest, Not a member yet? Register   Sign In
Post is always empty on live server
#1

Hello,
I put up my website on the prod server and there way the following problem:
When sending a form with method POST, nothing is received in the controller.


Informations:
  • When checking the developper tools of my browser, I see the request is sent with the correct method (POST) and the data are present.
  • When writing
    Code:
    var_dump($this->request->getPost())
    or
    Code:
    var_dump($_POST)
    in the controller, an empty array is displayed.
  • If I try to do the same request with Postman, the result is the same.
  • When trying a simple PHP page that doesn't use the Framework, everything works fine ⇒ it's probably CodeIgniter's fault (or, more plausibly, my configuration).
  • Everything Works Fine on My Machine™, but it doesn't in the server (well, the rest does, only the POST content is lost AFAIK).
  • The server is hosted by OVH.
  • The code has been tested with both PHP 7.4 and PHP 8.0.
Any chance one of you knows what I'm talking about and has a solution to explain? I'm willing to provide extended informations upon demand.

Thanks to whoever takes some time to answer!
Reply
#2

If you want help on this then you need to post your controller and html form code here for us to look at.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Here is my code:

The HTML code:


Code:
<form method="post" class="table">
    <label for="email">Adresse email</label>
    <input type="email" name="email" id="email" value="{email}" autofocus>
    <div>{+validation_errors field=email+}</div>
    <label for="password">Mot de passe</label>
    <input type="password" name="password" id="password">
    <div>{+validation_errors field=password+}</div>
    <button class="full-width">Se connecter</button>
</form>

The controller (method User::login):


PHP Code:
    public function login()
    {
        var_dump($this->request->getPost()); // array(0) { }
        var_dump($_POST); // array(0) { }
        $login $this->request->getPost();

        if ($this->request->getMethod() == 'post') {
            if ($this->validate('login')) {
                $this->auth->login($login);
                return redirect()->to('/');
            }
        }
        $this->useTables();
        $this->data['email'] = $login['email'] ?? '';
        $this->render();
    
Reply
#4

Your missing the action attribute.

PHP Code:
<form action="/controller/method" method="post"
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(This post was last modified: 10-19-2021, 02:51 AM by SteeveDroz.)

Additional information:

It seems that the response is sent twice, for example, if I contact the page with curl, I get 2 ci-session cookies.

I know that has been talked about on this forum before, but I checked all the potential missing links, nothing seems wrong.

(10-19-2021, 02:25 AM)InsiteFX Wrote: Your missing the action attribute.

PHP Code:
<form action="/controller/method" method="post"

No, if action is missing, the PHP_SELF page is used. It can't be that because the page is correctly displayed after the form is sent.

Other new information:

Code:
curl -i https://cramine.ch
returns HTTP/2 200

Code:
curl -I https://cramine.ch
returns HTTP/2 404
Reply
#6

(This post was last modified: 10-19-2021, 04:42 AM by SteeveDroz.)

The response was indeed sent twice. I am using a composer package that didn't adapt to the latest versions of CodeIgniter. I notified the developper and manually edited vendor in the meantime.

Thanks for all your help!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB