我这里有两个部分,一个是类别部分,另一个是登录部分。我希望可以通过 simpe 在 login.php 中访问所选类别,$cat = $_POST['logincategory']; echo $cat;
但所选单选值是不可访问的,并且在提交表单时出现错误:
Notice: Undefined index: logincategory
<section id="categorysection" action="login.php" form="loginform">
<ul style="font-size:20px; font-color:#000;">
<li> <input type="radio" name="logincategory" value="administrator"> Administrator </li>
<li> <input type="radio" name="logincategory" value="director"> Director (IQAC) </li>
<li> <input type="radio" name="logincategory" value="vicechancellor"> Vice Chancellor </li>
<li> <input type="radio" name="logincategory" value="registrar"> Registrar </li>
<li> <input type="radio" name="logincategory" value="facutly"> Faculty/Dept. Representative </li>
</ul>
<button id="logincategorybutton" type="submit" class="login-button" value="→ Login" hidden>Login</button>
</section>
<section id="loginsection" >
<form method="post" action="login.php" class="login" id="loginform">
<p>
<label for="username" style="color:#000; font-weight:700">Username:</label>
<input type="text" name="username" id="username" style="width:300px" required placeholder="enter username" maxlength="20">
</p>
<p>
<label for="password" style="color:#000; font-weight:700">Password:</label>
<input type="password" name="password" id="password" style="width:300px" required placeholder="enter password" maxlength="20">
</p>
<p class="login-submit">
<input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />
<button type="submit" class="login-button" onclick="document.getElementById('logincategorybutton').click();" value="→ Login">Login</button>
</p>
<!-- <p class="forgot-password"><a href="index.html">Forgot your password?</a></p>-->
</form>
<sup style="color:#000; padding-left:150px;"> ** both username and password must be alpha-numeric between 4-20 characters</sup>
</section>
</body>
编辑:在表单标签中带来了单选按钮,仍然面临同样的问题
<section id="categorysection" >
<form form="loginform">
<ul style="font-size:20px; font-color:#000;">
<li> <input type="radio" name="logincategory" value="administrator"> Administrator </li>
<li> <input type="radio" name="logincategory" value="director"> Director (IQAC) </li>
<li> <input type="radio" name="logincategory" value="vicechancellor"> Vice Chancellor </li>
<li> <input type="radio" name="logincategory" value="registrar"> Registrar </li>
<li> <input type="radio" name="logincategory" value="facutly"> Faculty/Dept. Representative </li>
</ul>
</form>
<button id="logincategorybutton" type="submit" class="login-button" value="→ Login" hidden>Login</button>
</section>