Hi guys.
My brain is fried after 10 hours of coding, so I need some help.
I have used the following function to retrieve data from a form submission (before I process the data, verifying input etc):
// All form fields are identified by '[id]_[name]', where 'id' is the
// identifier of the form type. Eg. brand, store etc.
// The field identifier we want to return is just the name and not the id.
public function getFormData() {
$formData = array();
foreach ($_POST as $key => $value) {
$name = preg_replace('!.*_!', '', $key);
if (is_array($value)) {
$formData[$name] = implode(',', $value);
} else {
$formData[$name] = $value;
}
}
return $formData;
}
Now I'm submitting the form using AJAX, so I'm not able to use this function any more.
My $_POST['formData'] string looks like this (short version):
"store_name=My+new+store&store_street1=Some+address&store_zipcode=1188"
My goal is to be able to execute the following code:
echo $formData['name'] //Displays 'Some address'
My jQuery code looks like this:
function processRegistration()
{
var formData = jQuery('#registerStore form').serialize();
jQuery.post("mypath/jquery_bll.php", { instance: 'processRegistration', formData : formData },
function(data)
{
alert('some test data here');
},"json");
How can I change my function to handle data from an Ajax call?