2013-07-25 52 views
-1

我在這裏有兩個部分,一個是類別部分,另一個是登錄部分。我想的是,選擇的類別可以在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="&rarr; 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="&rarr; 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="&rarr; Login" hidden>Login</button> 

</section> 
+1

@DontVoteMeDown'形式方法=「POST'是這個問題。這個問題是你的表單元素'logincategory'不在''

標籤 – AlexP

+0

但我補充形式=」,在登錄表單」以前的部分...不會讓它成爲表格的一部分嗎? –

+0

不會發布,只有表單中的輸入元素會發布。將當前的''標籤移到頂部的'

' – AlexP

回答

0

您需要將內形式的單選按鈕標籤。另外,您不能使用section標籤提交表單。

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="&rarr; 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> 
+2

**中國諺語**:「給一個人一條魚,你喂他一天,教一個人釣魚,你一輩子喂他。」 –

+0

Thanx幫助亞歷克斯,但這很明顯,把一切都放在一個單一的形式。由於一些CSS原因,我無法將它們放在一個表單中。 –

+1

@Fred點採取,但它更容易顯示在代碼比解釋。 – AlexP

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="&rarr; 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> 
+0

人們關心地看到,後一部分沒有直接放在表單標籤下,而是成爲了表單的一部分,所以現在我實際上可以將該部分放置在頁面的任何位置(這是我的情況所需要的實際上) –

+0

@Fred這是一個新的HTML5屬性,它是有效的,無線電選項將提交 - 僅適用於支持它的瀏覽器的用戶! – AlexP

+0

@AlexP好的謝謝。就我個人而言,我喜歡HTML5所提供的內容,並且對於很多方面而言,但我不會因爲表單而混淆它。最好的是,我保持獨立*,因爲它是*,直到每個人都有一個HTML5兼容的Web瀏覽器,這可能發生在... 5,10年?這是一個不錯的選擇,嘿,不要誤解我的意思,我只是爲了進化而已,但是「老派」方法(不是全部,但很多)都會有它的位置,甚至大部分都是形式。非常感謝洞察力,歡呼聲。 –

相關問題