0

Have a form with method=post, see below:

<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 itemCheckout add-cart formSubmitCheckout">Checkout</a>
</form>

And this is the JS that submits the form when user clicks over Checkout link (<a>):

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

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

The code redirects us to the proper location process.php as it should be, but the array $_POST is not being created. This is what I get in intellij:

inserir a descrição da imagem aqui

I've tried the same proccess in Firefox and Safari and the result is the same: no $_POST.

if (isset($_POST['string'])) { display something ...

Doing a console.log($('form').serialize()); inside $('.formSubmitCheckout'){... I can see the variable 'string' (this the variable name) string=type%3Dpurchase%26priceAmo.

So the point here is that the $_POST is not being created at php side in process.php.

Does someone knows what is happening and can explain how to fix it?

IgorAlves
  • 5,086
  • 10
  • 52
  • 83

1 Answers1

1

There are several solutions:

1) you can use $_REQUEST instead of $_POST

2) problem might be in .htaccess. To fix this you have to add this rule to htaccess:

RewriteRule ^includes/process.php - [PT]

3) make sure you have Read/Write permissions to the file "includes/process.php". if so: sudo chmod 0777 includes/process.php

4) add attr: enctype="application/x-www-form-urlencoded" to your form

5) check your php.ini. There should be: post_max_size = 8M variables_order = "EGPCS" then restart your server

Lexxusss
  • 542
  • 4
  • 10