I am serializing my form data, logging it, then sending it off to the PHP file, where is it returning null.
jQuery:
$('#preregister').submit(function () {
if(checkemail("prereg_email")) {
var data;
data = $(this).serialize();
console.log(data);
$('#imageloader').fadeIn();
$.ajax({
url: '/docs/adduser.php',
data: data,
processData: false,
contentType: false,
type: 'POST',
success: function ( data ) {
//console.log(data); //returns a string of the data.
var data = JSON.parse(data); //parses the string into an object.
console.log(data); //logs the object.
if (data.error) { alert(data.message); }
}
});
}
return false;
});
PHP:
<?php
$Return = array();
$Return["in"] = $_POST;
$Return["error"] = false;
$Return["message"] = "Nothing has happened.";
/* EMAIL */
$in_email = urldecode($_POST["prereg_email"]);
$Return["in_email"] = $in_email;
if (!filter_var($in_email, FILTER_VALIDATE_EMAIL)) {
$Return["error"] = true;
$Return["message"] = "Enter a valid email.";
}
if (!$in_email) {
$Return["error"] = true;
$Return["message"] = "Enter an email.";
}
str_replace('\\/', '/', json_encode($Return));
echo json_encode($Return);
?>
When the data comes back, it says:
Object {in: Array[0], error: true, message: "Enter an email.", in_email: ""}
Which is odd, because right before I send data, I log it, and it reads:
prereg_email=rbross3%40gmail.com
So... I should at least be getting $Return["prereg_email"]
right?
I think that it's because you are using processData: false,
try without it. .serialize() returns a string already so you don't need processData: false,