Send info with ajax to submit.php
pHeys guys, I've been playing around with this ajax call for a few days
now. I had it posting an email with no variables earlier, but now I can't
get the call to submit the form with a variable or without. Here is my
code:/p precode lt;form id=contactform method=post action=submit.phpgt;
lt;input type=text placeholder=Name name=username id=username /gt;
lt;input type=email placeholder=Your Email Address name=email id=email
/gt; lt;input type=button id=submit class=submit value=submitgt;lt;/agt;
lt;/formgt; /code/pre pAJAX:/p precodelt;script type=text/javascriptgt;
$(#submit).click(function(event){ var data =
$('#contactform').serialize(); event.preventDefault(); $.ajax({ url:
submit.php, type: POST, data: data, success: function() { alert(Success!);
} }); return false; }); }); lt;/scriptgt; /code/pre psubmit.php:/p
precodelt;?php $from = info@email.com; $usersubject = Thank You!;
$usermessage = Thank you for signing up!; $to = $_REQUEST['email'];
$subject = Form Info; ?gt; lt;?php $name = $_REQUEST['username']; $email =
$_REQUEST['email']; $message = Name: $name Email: $email; $headers = From:
. $from; //mail($to,$subject,$message,$headers);
mail($email,$usersubject,$usermessage,$headers); echo 'Success'; ?gt;
/code/pre psubmit.php works when you access it directly with the variable
(www.website.com/submit.php?username=Daveamp;email=davesemail@mail.com).
Is there an error somewhere here that I'm missing? Any help is
appreciated!/p
No comments:
Post a Comment