Answer the question
In order to leave comments, you need to log in
How to accept serialize() in php?
Friends, I can't accept serialize in php and print an array. Some kind of fool.
Was in JS
$.ajax({
type: "POST",
url: mailHandlerURL,
data: {
name: getValFromLabel($('.name', _.form)),
email: getValFromLabel($('.email', _.form)),
phone: getValFromLabel($('.phone', _.form)),
}
})
$email = "";
if (isset($_POST["email"])) {
$email = $_POST["email"];
}
$.ajax({
type: "POST",
url: mailHandlerURL,
data: form.serialize(),
success: function () {
console.log(_.form.serialize())
}
})
parse_str($_POST['serialize'], $email);
$email = $email['email'];
Answer the question
In order to leave comments, you need to log in
Why not use JSON? On the PHP side - using the json_decode function to convert back to an array
There is no element named serialize in the post, look in the browser at the data being sent
The $.serialize method casts the form field data to a query string format. The data property expects an object to be passed. Nothing needs to be converted to JSON - this is a game, all that is needed is to transfer the object normally. There are a bunch of implementations for this, here's a simple example: https://codepen.io/kpeatubho/pen/oEPrBm ($.serializeObject method) as a result, we have a normal object in the data variable, passing which we can work normally with POST data.
var_dump($_POST); what does it show? I bet $_POST['data'], which is where everything lies?
Get it out of it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question