Good afternoon. Write your AJAX form on Bitrix. But I can't understand what the bug is, why when you click on the button "Request a call" nothing why something happens.
In footer.php created markup for the form itself.
Form callback
callback.php that lies at the root of the website folder ajax
< ? define("NO_KEEP_STATISTIC", true);?>
< ? define("NOT_CHECK_PERMISSIONS", true); ?>
< ? define("NEED_AUTH", true); ?>
< ? require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); ?>
< ?
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
if(!empty($_POST['phone']) and !empty($_POST['name'])) {
$arEventFields = array (
"NAME" => strip_tags($_POST['name']),
"PHONE" => strip_tags($_POST['phone'])
);
if ($sended = CEvent::Send("CALLBACK", SITE_ID, $arEventFields)) {
$result['status'] = "success";
$result['message'] = "Your request successfully submitted";
} else {
$result['status'] = "error";
$result['message'] = "an error Occurred, please try again later";
}
} else {
$result['message'] = "Name and phone number required";
$result['status'] = "error";
}
exit(json_encode($result));
}
?>
ajax form submit
$(document).ready(function(){ $('#form-callback').on('submit', function(e) { $.ajax({ type: 'POST', url: $(this).attr('action'), data: $(this).serialize(), dataType: 'json', success: function(result){ if(result.status == 'success') { $('#form-callback').html(''+result.message+''); } if (result.status == 'error') { $('#form-callback .info-box').html(''+result.message+''); } } }); e.preventDefault(); return false; }) });
What's wrong here?