Form throwing error messages
When I submit my form, I get an the "You must write a message" echo from the PHP code, and I also get the error message from the ajax. I don't need the PHP echo messages because I have the ajax messages. Can't figure out the problem.
I would like to only use the ajax messages.
Here is the ajax:
Code:
$(function(){
$("#btnSend").click(function(){
$.ajax({type:'POST', url: './php/mailer.php', data:$('#frmContact').serialize(), success: function(response) {
$("#spanMessage").html('Please Wait...');
if(parseInt(response)>1)
{
$("#spanMessage").html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button><strong>Well done!</strong> Your message has been sent.</div>');
}
else{
alert(response);
$("#spanMessage").html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button><strong>Error! </strong> Somthing Wrong</div>');
}
}});
});
Here is the PHP:
PHP Code:
<?php session_start();
if(isset($_POST['Submit'])) {
$youremail = 'wjordan1987@gmail.com';
$fromsubject = 'Test Email';
$txtName = $_POST['txtName'];
$txtEmail = $_POST['txtEmail'];
$txtSubject = $_POST['txtSubject'];
$txtText = $_POST['txtText'];
$to = $youremail;
$mailsubject = 'Masage recived from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$txtName.'
E-mail: '.$txtEmail.'
Message:
'.$txtText.'
|---------END MESSAGE----------|';
echo "Thank you fo your feedback.";
mail($to, $subject, $body);
} else {
echo "You must write a message.";
}
?>
Here is the HTML form:
HTML Code:
<form action="" method="post" id="frmContact">
<h5>Whats your Name?</h5>
<input name="txtName" type="text" class="txbx" value="Name" /><br />
<h5>Whats your Email?</h5>
<input name="txtEmail" type="text" class="txbx" value="Email" /><br />
<h5>Email Subject?</h5>
<input name="txtSubject" type="text" class="txbx" value="Subject" /><br />
<div class="erabox">
<h5>Message to us</h5>
<textarea name="txtText" cols="" rows="" class="txbx era" value="Message" ></textarea><br />
<input name="Submit" type="button" class="sendbtn" value="Send Message" align="left" id="btnSend"/>
</form>