我只是想简单地验证表单中的字段,但由于某种原因,如果我没有在 mcHandle 字段中输入任何内容,我的 if 语句的 elseif 部分将不会回显 $errormsg 的值。
<?php include('header.php'); ?>
<div id="mainContent">
<?php
if ($_POST['submitted'] == 1) {
$errormsg = "";
if (isset($_POST['mcHandle'])) {
$mcHandle = $_POST['mcHandle'];
} else if (!isset($_POST['mcHandle'])) {
$errormsg ="Please enter your mc handle.";
echo("<p>".$errormsg."</p>");
}
}
?>
<div id="donateForm">
<form action="" method="post" enctype="multipart/form-data">
<ul>
<li><label>Minecraft Username:</label><input type="text" name="mcHandle" value=""></li>
<li><label>First Name:</label><input type="text" name="firstName" value=""></li>
<li><label>Last Name:</label><input type="text" name="lastName" value=""></li>
<li>
<label>Choose a plan:</label>
<select name="planName">
<option>Donator 2$/month</option>
<option>VIP 4$/month</option>
<option>Celebrity 6$/month</option>
<option>Saint 8$/month</option>
<option>Legendary 10$/month</option>
</select>
</li>
<li>
<label>How many months?</label>
<select name="planLength">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</li>
<li>
<br><input value="Submit" class="submit" type="submit">
<input type="hidden" value="1" name="submitted">
</li>
</ul>
</form>
</div>