F
F
freeman02042016-02-29 18:28:34
PHP
freeman0204, 2016-02-29 18:28:34

After submitting the form, data instead of variables does not come. Why?

html

<form action="#" id="form" method="GET">
                            <input type="text" name="fio" placeholder="ФИО*" required>
                            <input type="text" name="package" placeholder="Пакет*" required>
                            <input type="text" name="mail" placeholder="E-mail*" required>
                            <input type="text" name="tel" placeholder="Телефон*" required>
                            <input type="text" name="code" placeholder="Промокод">
                            <button class="btn">Зарегистрироваться</button>
                        </form>

js
$(document).ready(function() {

    $("#form").submit(function() {
        $.ajax({
            type: "GET",
            url: "mail.php",
            data: $(this).serialize()
        }).done(function() {
            $(this).find("input").val("");
            alert("Спасибо за заявку! Скоро мы с вами свяжемся.");
            $("#form").trigger("reset");
        });
        return false;
    });

});

php
<?php

$recepient = "[email protected]";
$sitename = "Новый участник";

$fio = trim($_GET["fio"]);
$package = trim($_GET["package"]);
$mail = trim($_GET["mail"]);
$tel = trim($_GET["tel"]);
$code = trim($_GET["code"]);


$message = "ФИО: $fio \nПакет: $package \nE-mail: $mail \nТелефон: $tel \nПромокод: $code";

$pagetitle = "Новая заявка с сайта \"$sitename\"";
mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $recepient");

Here's what comes screenshot.ru/0e0d102629422f5eb402618aa9ed9e70

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2016-02-29
@werty1001

try like this:

$(document).ready(function() {

  $("#form").submit(function() {
    var form = $(this);
    $.ajax({
      type: "POST",
      url: "mail.php",
      data: form.serialize()
    }).done(function() {
      form.find("input").val("");
      form.trigger("reset");
      alert("Спасибо за заявку! Скоро мы с вами свяжемся.");
    });
    return false;
  });

});

E
Eugene, 2016-03-01
@zolt85

The parameters of the GET request are passed in the URL of the request itself. You put everything in the request body, so $_GET[] does not contain anything on the server side. Those. You need to form a URL like
mail.php?fio="fio"&package="package" etc. Or leave everything as it is, change the request method to POST and take values ​​from $_POST on the server side, respectively.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question