this first time using php , haven't clue i'm doing. i've taken template , coded html form go it, works except there's no required fields can send blank email if click submit. i'd have error message come when 'name' , 'email' , 'message' inputs empty. can help?
<?php $emailfrom = "joejlomax@gmail.com"; $emailto = "joejlomax@gmail.com"; $subject = "t/v/c inquiry"; $name = trim(stripslashes($_post['name'])); $tel = trim(stripslashes($_post['tel'])); $email = trim(stripslashes($_post['email'])); $message = trim(stripslashes($_post['message'])); // validation $validationok=true; if (!$validationok) { print "<meta http-equiv=\"refresh\" content=\"0;url=error.php\">"; exit; } // prepare email body text $body = ""; $body .= "name: "; $body .= $name; $body .= "\n"; $body .= "email: "; $body .= $email; $body .= "\n"; $body .= "message: "; $body .= $message; $body .= "\n"; // send email $success = mail($emailto, $subject, $body, "from: <$emailfrom>"); // redirect success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;url=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;url=error.php\">"; } ?>
you can use empty check if variable is.. empty.
$validationok = true; if(empty($name) or empty($tel) or empty($email) or empty($message)) { $validationok = false; } if (!$validationok) { print "<meta http-equiv=\"refresh\" content=\"0;url=error.php\">"; exit; }
Comments
Post a Comment