PHP复选框动态名称并正确检索

时间:2017-09-19 18:46:19

标签: php forms checkbox dynamic

我有一个测验,一个测验有多个复选框问题。如何使所有复选框名称不同,以便我可以正确检索?

HTML:

foreach($questionSetArr as $question){
$questionID = $question['question_id'];
           $getListOfOptions = getOptionsList($questionID);
           foreach($getListOfOptions as $option){
               $optionDesc =  $option['option_desc'];
               echo "<div class='checkbox'>
               <label><input type='checkbox' value='$optionDesc' name='cb[$questionID]' id='$questionID' >$optionDesc</label>
               </div>";    
           }
}

PHP:

$questionID = $qIDArr[$x];
    echo "<br>User Answer for Question $questionID  : ";
                $selectedQuestion= $_POST["cb"];
        print_r($selectedQuestion);     
                foreach ($selectedQuestion as $sQ){
                    echo $sQ;
            }

目前,他们会错误地检索。 怎么解决? enter image description here

1 个答案:

答案 0 :(得分:0)

尝试这样命名:

名=&#39; CB [$ questionID] []&#39;