จะเช็คข้อที่ยังไม่มีคนตอบไดยังไงอะคับ ใครก็ได้ช่วยที

<legend><b>คำถาม</b></legend>
        <form name="formPoll" action="<?php echo $_SERVER['PHP_SELF']."?id=$topicid"; ?>" method="post" >
        <?php

        if(mysql_num_rows($resultQuiz) > 0){
            echo "<ol>";
        while($rowQuiz = mysql_fetch_assoc($resultQuiz)){
            $QuizId = $rowQuiz['QuestionId'];  
            echo "<input type='hidden' name='quizid[]' value='$QuizId'>";
            echo "<input type='hidden' name='quiztype[]' value='$QuizId'>";
            echo "<br><li><Strong>".$rowQuiz['Question']." ?</Strong><br>";
            $qtype = $rowQuiz['AnswerType'];
            $other = $rowQuiz['Other'];
            if($qtype != 'custom'){           
          $sqlShowChoice = "SELECT ChoiceId, Choice FROM Choice WHERE QuestionId = $QuizId Order By ChoiceId ASC";
          $result_choice = mysql_query($sqlShowChoice);
          while($rowChoice = mysql_fetch_assoc($result_choice)){
              if($rowChoice['Choice'] != 'อื่นๆ'){
              if($qtype == 'single'){
                       echo " <input type=\"radio\" name=\"".$QuizId."[]\" value=\"".$rowChoice['ChoiceId']."\"  >".$rowChoice['Choice']."<br>";   
                      }else if($qtype == 'multi'){
                       echo " <input type=\"checkbox\" name=\"".$QuizId."[]\" value=\"".$rowChoice['ChoiceId']."\"  >".$rowChoice['Choice']."<br>";   
                      } 
              }else{
                  if($qtype == 'single'){
                        echo $other == "1" ? " <input type=\"radio\" name=\"".$QuizId."[]\" value=\"".$rowChoice['ChoiceId']."\"  > อื่นๆ <input type=\"text\" name=\"txtother".$rowChoice['ChoiceId']."\"><br>"  : "";
                    }else if($qtype == 'multi'){
                        echo $other == "1" ? "<input type=\"checkbox\" name=\"".$QuizId."[]\" value=\"".$rowChoice['ChoiceId']."\"  > อื่นๆ <input type=\"text\" name=\"txtother".$rowChoice['ChoiceId']."\"><br>"  : "";
                    }
              }
             
            
          }
         
         
         
         
            }else{
              echo "<input type=\"text\" name=\"txt".$QuizId."\" ><br>";  
            }
           
           
           
          //echo "</li>";
        }
        echo "</ol>";

13 มี.ค. 2553 6 1,642

ปกติแล้ว ตัวเลือกเช่น checkbox หรือ radio ที่มีชื่อเป็น array หากไม่มีการเลือกตัวใดตัวหนึ่งในกลุ่มเลย เมื่อ submit มันจะไม่มีชื่อนั้นๆ ส่งออกไปครับ ดังนั้นเราก็ตรวจได้ว่ามีการเลือกหรือเปล่า

<input type="radio" name="radio[]" value="1" />
<input type="radio" name="radio[]" value="2" />


<?php
  if(!isset($_POST['radio'])){
    echo 'กรุณาเลือก';
  }
?>

#1

อ้างอิงจาก ความคิดเห็น #1

ปกติแล้ว ตัวเลือกเช่น checkbox หรือ radio ที่มีชื่อเป็น array หากไม่มีการเลือกตัวใดตัวหนึ่งในกลุ่มเลย เมื่อ submit มันจะไม่มีชื่อนั้นๆ ส่งออกไปครับ ดังนั้นเราก็ตรวจได้ว่ามีการเลือกหรือเปล่า

<input type="radio" name="radio[]" value="1" />
<input type="radio" name="radio[]" value="2" />


<?php
  if(!isset($_POST['radio'])){
    echo 'กรุณาเลือก';
  }
?>

ขอขอบคุณพี่แอดมินเป็นอย่างสูง

#2

ใช้จาวาสคิปที่ให้มัน alert ขึ้นมาทำไงอะพี่ ขอขอบคุณสำหรับคำตอบก่อนเลยนะคับ

#3

#4

เขียนยังไงอะคับบอกหน่อยซิ

#5

อ้างอิงจาก ความคิดเห็น #4http://www.goragod.com/knowledge-การตรวจสอบฟอร์มก่อนส่งว่ามีการเลือก%20checkbox(Array)%20ไว้หรือเปล่า.html
ตัวอย่างก็อยู่ในนั้นไง ถ้าใช้งานเลยไม่ได้ ก็ลองนำตัวอย่างไปรันดู ทำความเข้าใจ แล้วดัดแปลง
#6
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^