javascript - Email Form: $_POST is empty after form submit -
i've been on forums. general reason doesn't work need name attribute, not id. have name attribute , still empty $_post fields on submit. i'm beginner , have been @ 6 hours trying figure out. it's probablly simple. please help.
i got free template off shapebootstrap: https://shapebootstrap.net/item/1524963-evento-free-music-event-template
my html:
<form action="sendemail.php" method="post" name="contact-form" class="contact-form" id="main-contact-form"> <div class="form-group"> <input name="name" type="text" id="name" required="required" class="form-control" placeholder="name"> </div> <div class="form-group"> <input type="email" name="email" id="email" class="form-control" required="required" placeholder="email id"> </div> <div class="form-group"> <textarea name="message" id="message" required class="form-control" rows="10" placeholder="enter message"></textarea> </div> <div class="form-group"> <button type="submit" class="btn btn-primary pull-right">send</button> </div> <div> </div> </form>
my php:
<?php header('content-type: application/json'); $status = array( 'type'=>'success', 'message'=>'thank contact us. possible contact you' ); $name = ($_post["name"]); $email = ($_post['email']); $subject = "website message"; $message = ($_post['message']); $email_from = $email; $email_to = 'adam.wilson45@yahoo.com';//replace email $body = 'name: ' . $name . "\n\n" . 'email: ' . $email . "\n\n" . 'subject: ' . $subject . "\n\n" . 'message: ' . $message; $success = mail($email_to, $subject, $body, 'from: <'.$email_from.'>'); echo json_encode($status); die;
javascript:
// contact form validation var form = $('.contact-form'); form.submit(function () {'use strict', $this = $(this); $.post($(this).attr('action'), function(data) { $this.prev().text(data.message).fadein().delay(3000).fadeout(); },'json'); return false; }); $( window ).resize(function() { menutoggle(); }); $('.main-nav ul').onepagenav({ currentclass: 'active', changehash: false, scrollspeed: 900, scrolloffset: 0, scrollthreshold: 0.3, filter: ':not(.no-scroll)' }); });
thank in advanced!
you aren't passing data in $.post
script. change $.post($(this).attr('action'), function(data) {
$.post($(this).attr('action'), form.serialize(), function(data) {
. form.serialize()
bit passes object of form data php script.
see http://api.jquery.com/jquery.post/ more info.
Comments
Post a Comment