Skip to content

Commit

Permalink
minor_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolonin-Gleb committed Jan 23, 2024
1 parent aba5404 commit 2552b6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,14 @@ <h2 class="h_contact">Контакты</h2>
</div>
</div>

<!-- Поля для ввода user_email, user_name, text_comment пользователем -->
<div class="col-lg-6 order-lg-l ast order-first">
<div class="form">
<form class="d-flex flex-column">
<input class="in_text" type="email" id="user_email" placeholder="Ваш email" required>
<input class="in_text" type="text" id="user_name" placeholder="Ваше имя" required>
<textarea class="in_text" id="text_comment" cols="30" rows="5" placeholder="Сообщение" required></textarea>
<input class="submit" id="bth_submit" value="Отправить письмо" type="button" onclick="click_form()">
<input class="submit" id="bth_submit" value="Отправить письмо" type="button" onclick="clickForm()">
<div class="messages"></div>
</form>
</div>
Expand Down
4 changes: 2 additions & 2 deletions js/mail.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Функия для формы отправки письма
// Данные собранные из формы будут перенаправленны в mail.php
function click_form() {
console.log(1)
function clickForm() {
console.log(1);
// Collect data from the form
var user_name = $('#user_name').val();
var user_email = $('#user_email').val();
Expand Down
18 changes: 10 additions & 8 deletions mail.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
// Обработка данных пришедших из формы отправки письма.

<?php
// Обработка данных пришедших из формы отправки письма.

$msg_box = ""; // в этой переменной будем хранить сообщения формы
$errors = array(); // контейнер для ошибок
// проверяем корректность полей
if($_POST['user_name'] == "") $errors[] = "Поле 'Ваше имя' не заполнено!";
if($_POST['user_email'] == "") $errors[] = "Поле 'Ваш e-mail' не заполнено!";
if($_POST['text_comment'] == "") $errors[] = "Поле 'Текст сообщения' не заполнено!";

// если форма без ошибок
if(empty($errors)){
if(empty($errors)) {
// собираем данные из формы
$message = "Имя пользователя: " . $_POST['user_name'] . "<br/>";
$message .= "E-mail пользователя: " . $_POST['user_email'] . "<br/>";
$message .= "Текст письма: " . $_POST['text_comment'];
send_mail($message); // отправим письмо
sendMail($message); // отправим письмо
// выведем сообщение об успехе
$msg_box = "<span style='color: green;'>Сообщение успешно отправлено!</span>";
}else{
}
else {
// если были ошибки, то выводим их
$msg_box = "";
foreach($errors as $one_error){
foreach($errors as $one_error) {
$msg_box .= "<span style='color: red;'>$one_error</span><br/>";
}
}
Expand All @@ -32,7 +33,7 @@


// функция отправки письма
function send_mail($message){
function sendMail($message){
// почта, на которую придет письмо
$mail_to = "KoloninGS20@st.ithub.ru";
// тема письма
Expand All @@ -45,3 +46,4 @@ function send_mail($message){
// отправляем письмо
mail($mail_to, $subject, $message, $headers);
}
?>

0 comments on commit 2552b6b

Please sign in to comment.