Skip to content

Instantly share code, notes, and snippets.

@pvolyntsev
Last active June 6, 2016 13:31
Show Gist options
  • Save pvolyntsev/b1ce3d17c5fad20bffe3 to your computer and use it in GitHub Desktop.
Save pvolyntsev/b1ce3d17c5fad20bffe3 to your computer and use it in GitHub Desktop.

Revisions

  1. pvolyntsev revised this gist Jun 6, 2016. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,10 @@

    --
    [ [webmentor.pro](http://webmentor.pro/) ]
    Наставник и ментор по веб-технологиям
    Помощь в изучении веб-технологий
    Ревью кода Javascript Python NodeJS PHP HTML
    Консультации по проектированию и реализации веб-проектов
    Разработка индивидуальных планов самостоятельного изучения
    Передача навыков удалённой работы
    Передача навыков командной веб-разработки
    + Наставник и ментор по веб-технологиям
    + Помощь в изучении веб-технологий
    + Ревью кода Javascript Python NodeJS PHP HTML
    + Консультации по проектированию и реализации веб-проектов
    + Разработка индивидуальных планов самостоятельного изучения
    + Передача навыков удалённой работы
    + Передача навыков командной веб-разработки
  2. pvolyntsev revised this gist Jun 6, 2016. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,11 @@
    Для вопроса https://toster.ru/q/298504

    --
    Веб-ментор, наставник [ [webmentor.pro](http://webmentor.pro/) ]
    [ [webmentor.pro](http://webmentor.pro/) ]
    Наставник и ментор по веб-технологиям
    Помощь в изучении веб-технологий
    Ревью кода Javascript Python NodeJS PHP HTML
    Консультации по проектированию и реализации веб-проектов
    Разработка индивидуальных планов самостоятельного изучения
    Передача навыков удалённой работы
    Передача навыков командной веб-разработки
  3. pvolyntsev revised this gist Jun 6, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,5 @@

    Для вопроса https://toster.ru/q/298504

    Веб-ментор, наставник [ (webmentor.pro)[http://webmentor.pro/] ]
    --
    Веб-ментор, наставник [ [webmentor.pro](http://webmentor.pro/) ]
  4. pvolyntsev revised this gist Jun 6, 2016. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    # Пример кода, реализующего отправку email с сайта через AJAX запрос

    Для вопроса https://toster.ru/q/298504

    Веб-ментор, наставник [ (webmentor.pro)[http://webmentor.pro/] ]
  5. pvolyntsev revised this gist Mar 5, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion feedback.js
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ $(document).ready(function(){
    });

    function feedback_validate() {
    var result = false; // по умолчанию форма должна считаться невалидной
    var result = true;
    var f_names = ["#name-input", "#email-input", "#phone-input"];
    var el;

  6. pvolyntsev created this gist Mar 5, 2016.
    19 changes: 19 additions & 0 deletions feedback.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <div class="b-form-wrap">
    <p id="validation-fail-msg">Please, fill in the missing fields.</p>
    <form novalidate id="feedback-form">
    <div class="b-form-box">
    <p class="form-box__text form-box__text_no-pad">What's your name?<sup class="form-box__sup">*</sup></p>
    <input type="text" name="name" maxlength="30" required id="name-input" class="form-box__input-field">
    <p class="form-box__text">What's your phone number?<sup class="form-box__sup">*</sup></p>
    <input type="text" name="phone" maxlength="30" required id="phone-input" class="form-box__input-field">
    <p class="form-box__text">What's your email?<sup class="form-box__sup">*</sup></p>
    <input type="text" name="email" maxlength="50" required id="email-input" class="form-box__input-field">
    </div>
    <div class="b-form-box b-form-box_left-mrg">
    <p class="form-box__text form-box__text_no-pad">How can I help you?</p>
    <textarea name="text" class="form-box__input-field form-box__input-field_textarea"></textarea>
    </div>
    <input type="submit" class="form-box__button" value="Beautify me"><!-- <input type="submit" > вместо <button> -->
    <p id="validation-success-msg">Thanx, I'll contact you very soon.</p>
    </form>
    </div>
    48 changes: 48 additions & 0 deletions feedback.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    $(document).ready(function(){
    $("#feedback-form").submit(function(e){ // привязать обработку на submit а не на click
    e.preventDefault();
    if (feedback_validate()){
    $.ajax({
    type: "POST",
    url: "php/feedback.php",
    data: $(this).serialize()
    }).done(function() {
    $(this).find("input").val("");
    $('#validation-success-msg').show('fast');
    $("html, body").animate({
    scrollTop: $(document).height()
    }, "slow");
    $("#feedback-form").trigger("reset");
    });
    }
    return false;
    });
    });

    function feedback_validate() {
    var result = false; // по умолчанию форма должна считаться невалидной
    var f_names = ["#name-input", "#email-input", "#phone-input"];
    var el;

    f_names.forEach(function(item) {
    el = $(item);
    if (el.val() == "") {
    result = false;
    el.addClass("validation-error");
    } else {
    el.removeClass("validation-error");
    }
    });

    if (result) {
    $("#validation-fail-msg").hide();
    } else {
    $("#validation-fail-msg").show();

    $('html, body').animate({
    scrollTop: $("#validation-fail-msg").offset().top
    }, 1000);
    }

    return result;
    }
    17 changes: 17 additions & 0 deletions feedback.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    $recepient = "email here";
    $sitename = "site here";

    $name = trim($_POST["name"]);
    $phone = trim($_POST["phone"]);
    $email = trim($_POST["email"]);
    $text = trim($_POST["text"]);

    $subject = "A new submission from \"$sitename\"";
    $message = "Name: $name \nPhone number: $phone \nEmail: $email \nText: $text";
    $headers = array(
    "Content-type: text/plain; charset=\"utf-8\"",
    "From: $recepient",
    "Reply-To: $email", // чтобы при попытке ответить на письмо был подставлен адрес пользователя
    );

    mail($recepient, $subject, $message, implode("\r\n", $headers));