Z
Z
z_u_l2018-05-01 18:32:33
1C-Bitrix
z_u_l, 2018-05-01 18:32:33

Authorization form. Where is the mistake?

Good afternoon. I am writing my AJAX form on Bitrix. But I can't understand what the error is, why when you click on the "Order a call" button, for some reason nothing happens.
In footer.php I created the markup for the form itself.

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Форма обратного звонка</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form id="form-callback" action="ajax/callback.php">
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Имя:</label>
            <input type="text" class="form-control" name="name">
          </div>
          <div class="form-group">
            <label for="message-text" class="col-form-label">Телефон:</label>
            <input type="text" class="form-control" name="phone">
          </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <input class="btn btn-primary" type="submit" name="submit" value="Заказать звонок">
      </div>
    </div>
  </div>
</div>

callback.php, which is located in the root of the site in the ajax folder
< ? 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 has been submitted successfully";
} else {
$result['status'] = "error";
$result['message'] = "An error occurred, please try again later";
}
} else {
$result['message'] = "Name and phone number are required";
$result['status'] = "error";
}
exit(json_encode($result));
}
?>
ajax form submission
$(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('<p class="alert alert-success">'+result.message+'</p>');
        }
        if (result.status == 'error') {
          $('#form-callback .info-box').html('<p class="alert alert-danger">'+result.message+'</p>');
        }
      }
    });
    e.preventDefault();
    return false;
  })

});

What's wrong here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Spiridonov, 2018-05-01
@customtema

F12 Zhamk, then submit Zhamk and look in the console, then in the Network tab - what's going on. What goes, what goes, what comes.
PS Why are you opening and closing PHP tags so many times???

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question