我做了一点点,但不是很好。我想检查电子邮件是否以正确的格式有效,名称是否不包含数字以及如何添加验证以检查数学问题是否正确。有人可以帮忙吗?
<?php
$submitted = $_POST["submitted"];
if($submitted == "true")
{
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$subject = trim($_POST["subject"]);
$message = trim($_POST["message"]);
$answerbox = trim($_POST["answerbox"]);
if($name == "") print "<p>Please type your name.</p>";
if($subject == "") print "<p>Please type a subject.</p>";
if($email == "") print "<p>Please type a valid email address.</p>";
if($message == "") print "<p>Please type your message.</p>";
if($answerbox == "") print "<p>Please answer the math question.</p>";
}
?>
<form name="contact" action="form2.php" method="post">
<input type="hidden" name="submitted" value="true"/>
<label for="YourName">Your Name:</label>
<input type="text" name="name" class="required" />
<label for="YourEmail">Your Email:</label>
<input type="text" name="email" class="required"/>
<label for="Subject">Subject:</label>
<input type="text" name="subject" class="required" />
<label for="YourMessage">Your Message:</label>
<textarea name="message" class="required"></textarea>
<p class="c3">10 + 5 =<input type="text" name="answerbox" id="answerbox" /></p>
<fieldset>
<input type="submit" name="submit" id="submit" value="Send" class="required"/>
<input type="reset" id="reset" value="Reset"/>
</fieldset>
</form>