Hello,
I'm working on a email form which seems to work halfway and it doesn't seem to complete the process.
WHen i click the submit button I can see that the values appear in the url but it should return a success/failed message but with my script nothing happens..
any ideas as to how to fix this?
- <!doctype html>
<html>
<head>
<title>Submit form without refreshing the page</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" </script>
<script>
$(function()
{ $("#send").click(function()
{ $.ajax(
{ type: "POST",
url: "send.php",
data: $("#myform").serialize(),
cache: false,
success: function(response)
{ if(response == "done")
{ alert("Form submitted successfully!"); }
else
{ alert("Form submission failed!"); }
},
error:function(response){ alert(response); }
});
});
});
</script>
</head>
<body>
<form id="myform" >
Name: <br /><input type="text" name="name" id="name" /><br />
Email: <br /><input type="text" name="email" id="email" /> <br />
Message: <br /><textarea name="msg" id="msg"></textarea> <br />
<input type="submit" id="send" name="send" value="Submit" />
</form>
</body>
</html>
- <?php
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['msg'];
print_r($_POST);
if(!empty($name) && !empty($msg))
{ echo "done"; }
else
{ echo "fail"; }
?>