There is such a form with a handler for sending an application to the mail. Can you please tell me how to check the fields to fill in and the mail field, respectively, for the presence of @ in the address? You need the type of required only through jquery (in safari, required does not work).

document.getElementById('feedback-form').addEventListener('submit', function(evt) { var http = new XMLHttpRequest(), f = this; evt.preventDefault(); http.open("POST", "http://ravtest1.site88.net/pro-stroy/contacts.php", true); http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); http.send("nameFF=" + f.nameFF.value + "&phone=" + f.phone.value + "&contactFF=" + f.contactFF.value + "&messageFF=" + f.messageFF.value); http.onreadystatechange = function() { if (http.readyState == 4 && http.status == 200) { $('.msg-form').html("Спасибо за обращение! Мы свяжемся с Вами в ближайшее время."); f.messageFF.removeAttribute('value'); // очистить поле сообщения (две строки) f.messageFF.value = ''; } } http.onerror = function() { $('.msg-form').html("Извините, данные не были переданы"); } }, false); 
 <div class="msg-form"></div> <form method="POST" id="feedback-form"> <div class="box-input"> <label for="name">Введите имя</label> <input type="text" name="nameFF" id="name"> </div> <div class="box-input"> <label for="email">Введите e-mail</label> <input type="email" name="contactFF" id="email"> </div> <div class="box-input"> <label for="phone">Введите контактный телефон</label> <input type="tel" name="phone" id="phone"> </div> <div class="box-input"> <label for="vopr">Задайте вопрос</label> <input type="text" name="messageFF" id="vopr"> </div> <div class="box-button"> <button type="submit">Отправить</button> </div> </form> 

  • > in safari required does not work - Alexander Goncharov

1 answer 1

 function cheсk_str(str) { if (str.length>0) { return true; } else { return false; } } 

This is a string test

  function chek_mail(str) { if (str.indexOf('@')>0) { if ((str.indexOf('.',str.indexOf('@'))>0)&&(str.indexOf('.',str.indexOf('@')-str.indexOf('@')>1))){ return true; } else { return false; } } else { return false; } } 

This is an e-mail check, meaning: we are looking for @, if there is, we check availability. after @, and check to between. and @ were any characters. All this needs to be organized before the http.send () line

  document.getElementById('feedback-form').addEventListener('submit', function(evt) { if (check_str(f.nameFF.value) && check_str(f.phone.value) && check_str(f.messageFF.value) && chek_mail(f.contactFF.value)) { var http = new XMLHttpRequest(), f = this; evt.preventDefault(); http.open("POST", "http://ravtest1.site88.net/pro-stroy/contacts.php", true); http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); http.send("nameFF=" + f.nameFF.value + "&phone=" + f.phone.value + "&contactFF=" + f.contactFF.value + "&messageFF=" + f.messageFF.value); http.onreadystatechange = function() { if (http.readyState == 4 && http.status == 200) { $('.msg-form').html("Спасибо за обращение! Мы свяжемся с Вами в ближайшее время."); f.messageFF.removeAttribute('value'); // очистить поле сообщения (две строки) f.messageFF.value = ''; } } http.onerror = function() { $('.msg-form').html("Извините, данные не были переданы"); } }} else{ $('.msg-form').html("Вы ввели что-то не так"); } , false); function cheсk_str(str) { if (str.length>0) { return true; } else { return false; } } function chek_mail(str) { if (str.indexOf('@')>0) { if ((str.indexOf('.',str.indexOf('@'))>0)&&(str.indexOf('.',str.indexOf('@')-str.indexOf('@')>1))){ return true; } else { return false; } } else { return false; } } 
  • Can you write, please, on the example of one field with my code? - Alexander