I have a page-contact.php (i have my custom form)
<form id="contact-form" name="contact-form" method="post" action="">
<input type="text" name="name" placeholder="name"/>
<input type="text" name="email" placeholder="email"/>
<textarea rows="4" cols="50" name="message"
placeholder="message"> </textarea>
<input id="submit" type="submit" name="submit" value="send"/>
</form>
I have a my email_process.php (
<?php
$to = 'info@domain.com';
$subject = $_POST['name'];
$email = $_POST['email'];
$body = $_POST['message'];
$headers = 'From: '.$email;
$mailCheck = mail($to, $subject, $body, $headers);
if($mailCheck) echo 1;
?>
I have also a js file for echo my success message and error message. The js form seems to work. but email_process.php is not working. For hand coded html without wordpress, the form action work "email_process.php" I think wordpress handle the code different. Can someone help me with this?
$(document).ready(function(){
alertAnswer();
});
var check = 1;
function alertAnswer(){
$('#contact-form').submit(function(event){
event.preventDefault();
checkFormFill();
if(check == false) alert("you didn't answer my form");
else sendMessage();
});
}
function checkFormFill() {
check = 1;
$('#contact-form input[type="text"]').each(function(){
if($(this).val().length < 3) check = false
})
if($('#contact-form textarea').val().length < 3) check = false
}
function eraseFormData() {
$('#contact-form input[type="text"]').each(function(){
$(this).val('');
})
$('#contact-form textarea').val('');
}
function sendMessage() {
$.post('email_process.php',
{
name: $('input[name="name"]').val(),
email: $('input[name="email"]').val(),
message: $('textarea[name="message"]').val()
},
function(data) {
if(data == 1) {
$('#sendMessage').text("Thanks for contacting us.
We\'ll get back to you shortly.");
$('#sendMessage').css("margin-top","15px");
eraseFormData();
}
else $('#sendMessage').text("Sorry, an error occured.
Please try again!");
});
}
Aucun commentaire:
Enregistrer un commentaire