H
H
hypero2020-05-21 13:23:10
PHP
hypero, 2020-05-21 13:23:10

Submitting a form?

Hello.

There are such cards.
5ec6562a11331249197143.png

Clicking the button opens a modal window with a form. There is only one form.
It is necessary that when submitting the form, the desired header comes to the mail.
5ec65684166b7267607098.png

How can I do that?

js handler:

$('form').each(function() {
        $(this).submit(function () {
            var formID = $(this).attr('id'); // Получение ID формы
            var formNm = $('#' + formID);
            $.ajax({
                type: 'POST',
                url: 'form.php', // Обработчик формы отправки
                data: formNm.serialize(),
                success: function (data) {
                    // Вывод текста результата отправки в текущей форме
                    $('#modal-thank').arcticmodal();
                }
            });
            return false;
        });
    });


PHP handler:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['name'])) {$name = $_POST['name'];}
    if (isset($_POST['phone'])) {$phone = $_POST['number'];}
    $to = "[email protected]"; /*Укажите ваш адрес электронной почты*/
    $headers = "Content-type: text/plain; charset = utf-8";
    $subject = "$formData";
    $message = "Имя: $name \n\nТелефон: $phone \n\n";
    $send = mail ($to, $subject, $message, $headers);
    if ($send == 'true')
    {
        echo "<center>Спасибо за отправку вашего сообщения!</center>";
    }
    else 
    {
        echo "<center><b>Ошибка. Сообщение не отправлено!</b></center>";
    }
} else {
    http_response_code(403);
    echo "Попробуйте еще раз";
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Chuvilin, 2020-05-21
@alexanderchuvilin

Add a hidden input to your forms:

<input type="hidden" name="title" value="Заголовок соответствующего блока">

In the handler, according to the logic of your script, add:
if (isset($_POST['title'])) {$title = $_POST['title'];}

...

$message = "Заголовок: $title \n\nИмя: $name \n\nТелефон: $phone \n\n";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question