How to remove the download of the entire page after the form is submitted?

Is the most common form of written hands.
Handler
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
 if (isset($_POST['name'])) {$name = $_POST['name'];}
 if (isset($_POST['phone'])) {$phone = $_POST['phone'];}
 if (isset($_POST['text'])) {$text = $_POST['text'];}
 if (isset($_POST['formData'])) {$formData = $_POST['formData'];}

 $to = "artyomunder@gmail.com"; /*Specify the address of the ha which must be a letter*/
 $sendfrom = "support@sitename.ru"; /*Specify the address from which will come the letter is not real, it is necessary for the formation of the email header*/
 $headers = "From:" . strip_tags($sendfrom) . "\r\n";
 $headers .= "Reply-To: ". strip_tags($sendfrom) . "\r\n";
 $headers .= "MIME-Version: 1.0\r\n";
 $headers .= "Content-Type: text/html;charset=utf-8 \r\n";
 $subject = "$formData";
 $message = "$formData<br/-->
 <b>the name of the sent:</b> $name<br>
<b>Phone:</b> $phone<br>
<b>Message:</b>$text
";
 $send = mail ($to, $subject, $message, $headers);
 if ($send == 'true')
{
 echo '<center>Your message has been sent, thank you! Our Manager will contact You shortly.</center>';
}
else
{
 echo '<center>

<b>Error. The message was not sent!</b>

</center>';
}
}?>


Js
$(function(){
 $('.form-footer').on('submit', function(e){
e.preventDefault();
 var $that = $(this),
 formData = new FormData($that.get(0));
$.ajax({
 url: $that.attr('action'),
 type: $that.attr('method'),
 contentType: false,
 processData: false,
 data: formData,
 dataType: 'html',
 success: function(form){
if(form){
$that.replaceWith(form);
}
}
});
});
 });

Form
<form class="form-footer" action method="post">
 <div class="row">
 <div class="col-md-6 npl"><input type="text" name="name" class="input-medium placeh-white" placeholder="Your name"></div>
 <div class="col-md-6 npall"><input type="text" name="phone" class="input-medium placeh-white" placeholder="Your phone"></div>
 <div class="col-md-12 npall">
 <textarea placeholder="message" name="text" class="placeh-white"></textarea>
</div>
 <button class="btn-medium" type="submit" name="submit">Send</button>
</div>
</form>


All sends, but after sending loads the whole page in the place where they were form.
The website on Bitrix, what the fuck is this?
June 10th 19 at 15:36
3 answers
June 10th 19 at 15:38
Try removing the wrapper
$(function(){ ... })
Once the page is overloaded, so do not work out the script, there is a bug somewhere. What says the console?
Page not perezagruzite, everything is OK the Form is submitted without rebooting it, but then in the place where the form is loaded the whole page of the website - vladimir76 commented on June 10th 19 at 15:41
And then in server side you need to look for the error.
Try the form's action to register the full path to the handler. - rhianna_Fee commented on June 10th 19 at 15:44
June 10th 19 at 15:40
js is working fine, the problem is that the server gives you a "full page".

Stupid fix:
echo '<center>Your message has been sent, thank you! Our Manager will contact You shortly.</center>';
exit; /* in this place php shuts down */


And for good, it would be nice to deal with your CMS.
not prokanaet - vladimir76 commented on June 10th 19 at 15:43
and form accurately to the handler gets?
or maybe it returns <b>Error. The message was not sent!</b>, and then "whole page"? - rhianna_Fee commented on June 10th 19 at 15:46
Exactly what you need :) - vladimir76 commented on June 10th 19 at 15:49
he even first says "Your message has been sent, thank you! Our Manager will contact You soon." and then loads the whole site instead of labels - Austen.Thompson53 commented on June 10th 19 at 15:52
June 10th 19 at 15:42
Move the handler into a separate file. Apparently, it is called "surrounded by" the rest of the page
To make it like this:
<?
//The minimum prologue — if you want to use Bitrix-API
require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');

//Your handler
***
?>


Using Ajax send the data to him in answer, take text or JSON.

Find more questions by tags PHPjQueryAJAX1C-Bitrix