我很苦苦地用PHP,并且想在我的电子邮件字段中添加一些非常简单的验证,以便用户的电子邮件地址必须包含“@”。PHP表单验证 - 简单
请有人可以帮助我。我知道有很多其他类似的线程,但是,我似乎无法通过使用其他线程纠正我的代码。
我真的很感谢这方面的帮助,但我的确要求,如果您有足够的帮助,请尽量不要重组我的代码太多,因为我希望尽可能简单地使用我的现有代码代码到位。
HTML代码:
<form action="Scripts/studentinfo.php" method="get" id="studentinfo" onsubmit="return checkform()">
<fieldset>
<legend> Get in Contact </legend>
<label>
Email Address: <input type="text" name="email" value="your email address" />
</label>
<label>
What department would you like to contact?
<select name="subject">
<option value="Complaint">Complaint</option>
<option value="Website Issue">Website Issue</option>
<option value="General Enquiry">General Enquiry</option>
</select>
</label>
<br/>
<label>
First Name: <input type="text" name="Firstname" value="first name" />
</label>
<label>
Last Name: <input type="text" name="Lastname" value="last name" />
</label>
<label>
Gender
<br/>
Male:
<input type="radio" name="sex" value="male" checked="checked" />
Female:
<input type="radio" name="sex" value="female" />
</label>
<label>
<textarea rows="4" cols="15" name="comment" value="please tell us what you think"> </textarea>
</label>
<input type="submit" name="submit" value="Submit" />
PHP代码:
<head>
<link rel="stylesheet" type="text/css" title="Main Stylesheet" href="/stylesheet.css" />
<link rel="alternate stylesheet" type="text/css" title="Alternative Stylesheet" href="/alternate%20stylesheet.css" />
</head>
<?php
// pull out the values from the request stream sent by the form
// and store those values into memory variables
$email = $_REQUEST['email'];
$webmail = $_REQUEST['subject'];
$firstName = $_REQUEST['Firstname'];
$lastName = $_REQUEST['Lastname'];
$sex = $_REQUEST['sex'];
$to = 'email address';
$comment =$_REQUEST['comment'];
$subject =$_REQUEST['subject'];
$header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"';
$header .= ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
$htmlhead = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">';
$htmlhead .= '<head><title>Feedback Recieved</title>';
$htmlhead .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>';
$htmlbody = '<body>';
// use the variables that store the information sent from the form.
mail($to, $subject,"You have received the following feedback:". $comment, "from " . $firstName . " " . $lastName, "From: $email");
$htmlbody .= "<center><h1>Thank You</h1>";
$htmlbody .= "<p><b>" . $firstName . " " . $lastName ;
$htmlbody .= "</b>, we've recieved an email from your email address: <b>" . $email . "</b>, and will respond as soon as possible!</p></center>";
$htmlbody .= "</body></html>";
// use echo to write all the information out back to the browser
echo $header . $htmlhead . $htmlbody ;
echo '<center>To return, click <a href="/is0502/index.html">here</a>.</center>';
?>
在提交之前使用javascript来限定用户输入。 – Martin