-1

ここには 2 つのセクションがあります。1 つはカテゴリ セクション、もう 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

以下は修正後のコードです。

すべての入力要素をフォームにラップする必要があります。フォームごとに 1 つしか必要ないため、2 つ目の送信ボタンも削除したことに注意してください。

<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 に答える
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 に答える
0

form タグにラジオ ボタンを配置する必要があります。また、sectionタグを使用してフォームを送信することはできません。

于 2013-07-25T20:30:17.580 に答える