I am sending data from jquery via AJAX Post with all the form fields serialized (In WordPress).
$('#SendEmail').click(function () {
jQuery.post(
the_ajax_script.ajaxurl,
{
'action': 'the_ajax_hook_SendEmailWithCalculatorContent',
'calculatorFormContent': $("#CalculatorForm input").serialize()
},
function (response_from_the_action_function) {
$("#G1").val(response_from_the_action_function);
}
);
});
Here are the post paramters from firebug POST:
action the_ajax_hook_SendEmailWithCalculatorContent
calculatorFormContent ZIPCodeTextBox=01915&G1=PhoneNumber+%3A++ZipCode+%3A+&G2=&G3=&G4=&G5=&G6=&G7=&G8=&G9=&G10=&G11=&G12=&G13=&G14=&G15=&G16=&G17=&G18=&G19=&G20=&G21=&G22=&G23=&G24=&G25=&G26=&G27=&fullname=&email=&phone=7324211531
Need to access these parameters in PHP, when I try to access them
echo "PhoneNumber : ".$_POST['phone']." ZipCode : ".$_POST['ZIPCodeTextBox']." IndexValue : ".$_POST['0'];
I get the output as “PhoneNumber : ZipCode : IndexValue : “, so all the form data is coming as blanks.
When I try:
echo $_POST;
i see value “Array” come across.
How do I access the array value?
Saw multiple posts here that answer by using the parameter name, one can fetch data from $_POST[‘name’]. (Similar link: jQuery AJAX form data serialize using PHP)
But apparently it is not working in my case.
What about
'calculatorFormContent': JSON.stringify($("#CalculatorForm input").serializeArray())
and then in your PHP script use$array = json_decode($_POST['calculatorFormContent'], true);
Later access it with
$array['phone']
.