rm-vanda
rm-vanda

Reputation: 3158

$_REQUEST works, but $_POST doesn't -

Thank you for sharing in my headache - here is the short speil:

Recently inherited a poorly coded WordPress site - which leveraged a WP Contact Form 7 -

I stripped all the WP-CF code out (due to the fact that the WordPress had been stripped out before it was handed over to me) -- just to make a simple patch script and get on with real work.

I replaced the WPCF scripts with this one: (to make things as easy as possible for me):

jQuery(document).ready(function() {
 $ = jQuery;
 console.log("Ready");
 $("#quack-button").click(function(e) {
   console.log("Quack"); 
   e.preventDefault();
   e.stopPropagation();
   POSTDATA = $.param($("#quack-form").serializeArray());
   $.ajax({
     method : "POST",
     url : "http://www.domain.com/contact.php",
     data : POSTDATA,
     success : function(response) {
      console.log(response);
      alert("Thank you ! We'll get in touch as soon as we can -! ");
     }
   });
 });
});

but, after trying many different forms/combinations of $.param and serialize - The server side script continued to return a blank array....

print_r($_POST);

However, when I changed it to print_r($_REQUEST) - it all worked, fine....

Now, what possible ways could this even happen? What blindspots am I missing that could create this sort of scenario...?

This is the most baffling I've dealt with in some time... I appreciate any understanding anyone can throw at this...

Upvotes: 2

Views: 710

Answers (1)

Kevin
Kevin

Reputation: 41885

If you want to send it as $_POST, change this line:

method: 'POST'

to this:

type: 'POST'

According to docs, thats the way of setting it.

type (default: 'GET')
Type: String
The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

Upvotes: 8

Related Questions