-1

我这里有两个部分,一个是类别部分,另一个是登录部分。我希望可以通过 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="&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>
4

3 回答 3

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>
于 2013-07-25T21:09:46.580 回答
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>
于 2013-07-25T20:43:43.340 回答
0

您需要将单选按钮放在表单标签内。此外,您不能使用section标签来提交表单。

于 2013-07-25T20:30:17.580 回答