Answer the question
In order to leave comments, you need to log in
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
https://yadi.sk/i/YN-YVXJPyOgmrQ the line with the handler is commented out
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!
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");
}
$message = "Имя: $name \n
E-mail: $email \n
Телефонный номер: $phone\n";
$message = "Имя: ".$name." \n
E-mail: ".$email." \n
Телефонный номер: ".$phone."\n";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question