我已经尝试了很长时间来弄清楚为什么这个表格不起作用。如果您不输入任何内容,它甚至不会显示错误消息。
我希望这里有人能指出问题所在。
该表单经过 XHTML Strict 验证。
<?php
$err = array();
if (isset($_POST['submit'])) {
/* Do the validation */
$uploader_name = $_POST['uploader_name'];
$uploader_mail = $_POST['uploader_mail'];
if (empty($uploader_name)) {
$err[] = "Name is empty.";
}
if (empty($uploader_mail)) {
$err[] = "Mail is empty.";
}
/* If everything is ok, proceed */
if (empty($err)) {
//Do MySQL insert
}
}
echo "<h1>Submit</h1>";
if(!empty($err)) {
echo "<span style='color:red;'>";
foreach ($err as $e) {echo "* $e<br />"; }
echo "</span><br />";
}
echo "
<div>
<form action='' method='post' enctype='text/plain'>
<fieldset>
<legend>Your details</legend>
<label for='uploader_name'>Your name / nickname</label><br />
<input type='text' id='uploader_name' value='$uploader_name' /><br /><br />
<label for='uploader_mail'>Your mail (will not be visible)</label><br />
<input type='text' id='uploader_mail' value='$uploader_mail' /><br /><br />
</fieldset>
<p><input type='submit' id='submit' value='Submit' /></p>
</form>
</div>
";
?>