Для вопроса https://toster.ru/q/298504
Веб-ментор, наставник [ (webmentor.pro)[http://webmentor.pro/] ]
Для вопроса https://toster.ru/q/298504
Веб-ментор, наставник [ (webmentor.pro)[http://webmentor.pro/] ]
| <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> |
| $(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 = true; | |
| 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; | |
| } |
| $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)); |