我在這裏有兩個部分,一個是類別部分,另一個是登錄部分。我想的是,選擇的類別可以在login.php中通過simpe $cat = $_POST['logincategory']; echo $cat;
進行訪問,但所選擇的無線電值是可訪問的,並在提交表單的錯誤顯示出來說: Notice: Undefined index: logincategory
在提交另一個表單時使用PHP訪問值
<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>
@DontVoteMeDown'形式方法=「POST'是這個問題。這個問題是你的表單元素'logincategory'不在''
但我補充形式=」,在登錄表單」以前的部分...不會讓它成爲表格的一部分嗎? –
不會發布,只有表單中的輸入元素會發布。將當前的'