PHP $_POST is not being created when you submit the form

Asked

Viewed 45 times

0

I have a form whose method is POST:

<form action="/includes/process.php" method="post">        
    <input type="hidden" name="breakDown" value="1" />
    <input type="hidden" name="string" value="2" />
    <a href="javascript:;" class="btn btn-primary add-cart formSubmitCheckout">Checkout</a>
</form>

And this is the javascript that makes the form Submit.

   $('.formSubmitCheckout').click(function() {
        var t=$(this);
        var isItemCheckout = t.hasClass('itemCheckout');
        var form = t.parents('form');

        if(!isItemCheckout) {console.log('testOk');
            form.submit();
        }
    });

The fact is that when you press the link that simulates a Submit button the data is not being sent to process.php, that is, the array $_POST is not being created. inserir a descrição da imagem aqui

I’ve never been through this. Does anyone know what it might be? Because $_POST is not being generated or sent?

UPDATE:

I have this following test on process.php

if (isset($_POST['string'])) {

And making a console.log($('form').serialize()); i can see the variable 'string' (the variable name is string) string=type%3Dpurchase%26priceAmo .

  • Which IDE you are using, because you were using Jetbrains' PHP Storm and you had a problem just like this. $_POST only appeared when I ran on the same server outside the test server that was generated by the IDE.

  • tries to give a console.log($('form').serialize()) to see if the fields are right.

  • 1

    @Grupocdsinformática also had this problem with the Jetbrains IDE to bypass I created virtual server direct in php via console, php -S localhost:8080

  • But it’s not just the absence of $_POST in the Intellij debug. Actually if I turn off the intellij and run the script the $_POST tbm array does not appear. I think it has something to do with the browser. But until yesterday I didn’t have this error and I didn’t do any update.

  • 1

    @What I did was edit the files directly from the server (in my case my dev machine) and PHP ran on IIS. But that way I didn’t know it was, really. Excellent addition.

  • @zwitterion even tried to replace <a> with an input from Submit itself?

  • I could reproduce the problem but could not find the solution. The problem is the variable string. If I remove it, it works. I’ve tried increasing max_input_vars in php.ini, but it didn’t work. If I use file_get_contents("php://input");' I see the values in the target file. But the POST array is not generated. That’s what I don’t understand. What’s causing the POST array to break.

Show 2 more comments

1 answer

0

Try it this way

 $('.formSubmitCheckout').click(function() {
    var t=$(this);
    var isItemCheckout = t.hasClass('itemCheckout');
    var form = $('form');

    if(!isItemCheckout) {console.log('testOk');
        form.submit();
    }
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.