我这里有两个部分,一个是类别部分,另一部分是登录部分。我希望可以通过simpe $cat = $_POST['logincategory']; echo $cat;
在login.php中访问所选类别,但所选的无线电值是无法访问的,并且在提交表单时出现错误,显示:
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>
答案 0 :(得分:1)
以下是修订后的代码。
所有输入元素都需要包装在表单中。请注意,我还删除了第二个提交按钮,因为每个表单只需要一个。
<form method="post" action="login.php" class="login" id="loginform">
<section>
<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>
</section>
<section id="loginsection" >
<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>-->
<sup style="color:#000; padding-left:150px;"> ** both username and password must be alpha-numeric between 4-20 characters</sup>
</section>
</form>
答案 1 :(得分:1)
<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" value="→ Login">Login</button>
</p>
<!-- <p class="forgot-password"><a href="index.html">Forgot your password?</a></p>-->
</form>
</section>
<section id="categorysection" >
<form form="loginform">
<ul style="font-size:20px; font-color:#000;">
<li> <input type="radio" form="loginform" name="logincategory" value="administrator"> Administrator </li>
<li> <input type="radio" form="loginform" name="logincategory" value="director"> Director (IQAC) </li>
<li> <input type="radio" form="loginform" name="logincategory" value="vicechancellor"> Vice Chancellor </li>
<li> <input type="radio" form="loginform" name="logincategory" value="registrar"> Registrar </li>
<li> <input type="radio" form="loginform" name="logincategory" value="facutly"> Faculty/Dept. Representative </li>
</ul>
</form>
</section>
答案 2 :(得分:0)
您需要将单选按钮放在表单标记内。另外,您无法使用section
代码提交表单。