javascript - validate contact form with jquery and php -
i'm trying validate contact form jquery , php false php though it's working fine. i'm going explain code:
html:
<form method='post'> <label>name<input id="name" type="text" name="name" /></label> <label>email address<input id="email" type="text" name="email" /></label> <label>subject<input id="subject" type="text" name="subject" /></label> <label>message<textarea id="message" name="message"></textarea></label> <label><input type="button" value="submit form" id="button_form" /></label> </form> this js code:
function validaform(){ // campos de texto if($('#email').val() == ""){ alert("you must fill in @ least email field."); $('#email').focus(); return false; } return true; } $('#button_form').click( function() { if(validaform()){ $.post("php/form.php",$('form').serialize(),function(res){ if(res == 1){ alert("your e-mail has been sent, thank contacting us. answer possible."); } else if(res == 0){ alert("sorry, e-mail couldn't been sent, please try again later."); } else { alert("others."); } }); } }); this .php file:
<?php require 'class.phpmailer.php'; $mail = new phpmailer(); $mail->issmtp(); $mail->host = 'smtp.domain.com'; $mail->smtpauth = true; $mail->username = 'myacc@mydomain.com'; $mail->password = 'pass'; $mail->smtpsecure = 'tls'; $mail->from = 'myacc@mydomain.com'; $mail->fromname = 'contact form'; $mail->addaddress('myacc@mydomain.com'); $mail->addattachment('/var/tmp/file.tar.gz'); $mail->addattachment('/tmp/image.jpg', 'new.jpg'); $mail->ishtml(true); $mail->subject = $_post['subject']; $mensajefinal = "message"; $mail->body = $mensajefinal; if(!$mail->send()) { return false; } else { return true; }; ?> ok, working fine, mean, sends e-mail problem false php file no matter if sends or not e-mail.
doing wrong?? there missing??
appreciate help. thanxs lot.
you have use echo here, not function. return used returning result functions. remove ; after
else {...}; ^ if(!$mail->send()) { echo false; } else { echo true; }
Comments
Post a Comment