douweibiao8471 2018-09-25 02:38
浏览 74

如何使用复选框列表验证测试?

I have a checkbox list with 10 options ik the image just have 9:

and a db:

How can I compare the input in the checkbox list with the information inside the column requerimientos in my db?, it means values from the checkbox list must contain all of the values from requerimientos and it will happen with every id, just i didn't fill the other values yet, hope this clarify it

This is what I got, if it seems I have no clue what I am doing it can't be more accurate, but I dont give up. XD

<form action="" method="post">
    <?php
        $query = $mysqli->query("SELECT idclasificacion,clasificacion FROM clasificacion");
        while ($rows = $query->fetch_array()) {
            echo'<div class="list-group-item"  id='. $rows['idclasificacion'] .'>
                <label>
                    <input type="checkbox" name="requerimiento[]" id="" value="'.$rows['clasificacion'].'">'. $rows['clasificacion'] . '
                </label>
            </div>';
        }
    ?>
    <button class="btn btn-primary" type="submit">Ingresar</button>
</form>


<?php            
    //extrae los requerimiento seleccionados en forma de string, notar que requerimiento va sin []
    if (isset($_POST['requerimiento'])){                
        $requerimientos = implode ( ',', $_POST['requerimiento']);
        echo $requerimientos;
    }else {
        echo'no ha selecionado ningun requerimiento para su evento';
    }        

    echo '<br>';            

    $query = $mysqli->query("SELECT requerimientos FROM tipologia");
    $rows = $query->fetch_assoc();            
    var_dump($rows);
    $requetipo=explode(',', $rows['requerimientos']);
    var_dump($requetipo);
    $validacion=in_array($requerimientos,$requetipo);
    var_dump ($validacion);                        
?>
  • 写回答

1条回答 默认 最新

  • doujugu1722 2018-09-26 00:37
    关注

    tthis code compare the checked options, with the data inside requerimientos and if both are equal returns true if not false.

    Now i just need to do the other options hope a for loop will help me XD

    <?php            
                //extrae los requerimiento seleccionados en forma de string, notar que requerimiento va sin []
                if (isset($_POST['requerimiento'])){                
                    $requerimientos = implode ( ',', $_POST['requerimiento']);
                       // echo $requerimientos;
                }else {
                    echo'no ha selecionado ningun requerimiento para su evento';
                }        
                
                echo '<br>';            
    
                $query = $mysqli->query("SELECT requerimientos FROM tipologia where tipologia='Conferencia'");
                $rows = $query->fetch_assoc();
                if($requerimientos==$rows['requerimientos']){
    echo 'right';
    }else{
        echo 'wrong';
    }

    </div>
    
    评论

报告相同问题?