V
V
Vadim Yagofarov2019-04-07 08:55:47
JavaScript
Vadim Yagofarov, 2019-04-07 08:55:47

Ajax not firing on form submission?

Here is the site . Ajax does not work when submitting a form. The data is sent to the mail, but when sending, there is a transition to the handler, and ideally, when sending, there should be an alert with a message. Before that, I used bootstrap modal, this time I use remodal.js, but I doubt that this is the case. Tell me what is the error & how to catch such errors in devtools? Nothing unusual appears in the console

Here is the handler code

<?php
if (isset($_POST['name'])) {$name = $_POST['name']; if ($name == '') {unset($name);}}
if (isset($_POST['email'])) {$email = $_POST['email']; if ($email == '') {unset($email);}}
if (isset($_POST['tel'])) {$phone = $_POST['tel']; if ($phone == '') {unset($phone);}}
if (isset($_POST['message'])) {$message = $_POST['message']; if ($message == '') {unset($message);}}
if (isset($name) && isset($email)){
if ($_POST['form']) {$formType = $_POST['form'];}
$address = "[email protected]";
$message = "Имя: $name \n
E-mail: $email \n
Телефонный номер: $phone\n";
$send = mail($address,"Заполнена контактная форма на сайте RONAWEB.RU",$message,"Content-type:text/plain; charset = UTF-8"); 

}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Proger, 2019-04-07
@freekirill

https://yadi.sk/i/YN-YVXJPyOgmrQ the line with the handler is commented out

S
senior65, 2019-04-07
@senior65

Where the form with the button is located, write the attribute onclick="return false"
For example: Thus, we prevent the transition to the handler, and let Ajax work. There are several variations: return false; e.preventDefault; e.stopPropagation; Google them for them!

A
ARX2, 2019-04-07
@ARX2

Open var_dump($_POST);

<?php
if (isset($_POST['name'])) {$name = $_POST['name']; if ($name == '') {unset($name);}}
if (isset($_POST['email'])) {$email = $_POST['email']; if ($email == '') {unset($email);}}
if (isset($_POST['tel'])) {$phone = $_POST['tel']; if ($phone == '') {unset($phone);}}
if (isset($_POST['message'])) {$message = $_POST['message']; if ($message == '') {unset($message);}}
if (isset($name) && isset($email)){
if ($_POST['form']) {$formType = $_POST['form'];}
var_dump($_POST);
die;
$address = "[email protected]";
$message = "Имя: $name \n
E-mail: $email \n
Телефонный номер: $phone\n";
$send = mail($address,"Заполнена контактная форма на сайте RONAWEB.RU",$message,"Content-type:text/plain; charset = UTF-8"); 

}

Then you click f12 -> network -> monitor your ajax request -> see what POST returns and check against the conditions
--------------------------- ---------------
$message = "Имя: $name \n
E-mail: $email \n
Телефонный номер: $phone\n";

What for you here variables transfer as normal lines?
If you want to insert the contents of the variables here, then it should look like this:
$message = "Имя: ".$name." \n
E-mail: ".$email." \n
Телефонный номер: ".$phone."\n";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question