samedi 7 mai 2016

Display filters according checkbox

I wan't to affiche some filter according the checkbox statue. Without anything checked, the two form look like that :

The two forms of my page

But I want to hide some filter where his checkbox isn't checked. So, for that, I use this code :

<!DOCTYPE html>
<html>
  <head>
        <link rel="stylesheet" href="css/style.css">
        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </head>
  <body>

      <?php 
      include('fonctionsBDD.php');
      $bdd = connectionBDD(); 

      session_start();
      ?>

      

  
     <!-- Choix des filtres à afficher -->

     <p>Quels filtres afficher ?</p>

    <form action="" method="POST">
      <input type="checkbox" name="cbx-zones">Zones</input> 
      <input type="checkbox" mname="cbx-salles">Salles</input>
      <input type="checkbox" name="cbx-dates">Date</input> 
      <input type="checkbox" name="cbx-heures">Heures</input> 
      <p><input type="submit" /></p>
    </form>

    <!-- Zone filtres -->
    <div class="FiltreSalle">

    <form action="" method="POST">

    <?php 
      if (isset($_POST['cbx-zones'])) {
      /* FILTER HERE */
}

    ?>

But, when I push a filter on, the page display nothing. I have also test close ?> after the first } and re-open after my code, nothing.

This is my full page code :

<!DOCTYPE html>
<html>
  <head>
        <link rel="stylesheet" href="css/style.css">
        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </head>
  <body>

      <?php 
      include('fonctionsBDD.php');
      $bdd = connectionBDD(); 

      session_start();
      ?>

      

  
     <!-- Choix des filtres à afficher -->

     <p>Quels filtres afficher ?</p>

    <form action="" method="POST">
      <input type="checkbox" name="cbx-zones">Zones</input> 
      <input type="checkbox" mname="cbx-salles">Salles</input>
      <input type="checkbox" name="cbx-dates">Date</input> 
      <input type="checkbox" name="cbx-heures">Heures</input> 
      <p><input type="submit" /></p>
    </form>

    <!-- Zone filtres -->
    <div class="FiltreSalle">

    <form action="" method="POST">

    <?php 
      if (isset($_POST['cbx-zones'])) {
      /* COntenu d'un filtre ici */
}

    ?>
    <!-- Filtre par Area Name-->

<form action="" method="POST">
    <br /><br />

    <label>Choisir la zone </label><br />

    <select name="utilisateur">
     
    <?php
     
    $reponseSalle = $bdd->query('SELECT * FROM mrbs_area ORDER BY area_name');


     
    while ($donnees = $reponseSalle->fetch(PDO::FETCH_OBJ))
    {
    ?>
               <option value="<?php echo $donnees->id; ?>"> <?php echo $donnees->area_name; ?></option>
    <?php
    }
     
    ?>
    </select>

    <!-- Filtre par salle -->
       <br /><br />

    <label for="salle">Choisir la salle</label><br />

    <select name="salle">
     
    <?php
     
    $reponseSalle = $bdd->query('SELECT * FROM mrbs_room ORDER BY room_name');


     
    while ($donnees = $reponseSalle->fetch(PDO::FETCH_OBJ))
    {
    ?>
               <option value="<?php echo $donnees->id; ?>"> <?php echo $donnees->room_name; ?></option>
    <?php
    }
     
    ?>
    </select>

    <!-- Filtre par utilisateurs-->

    <br /><br />

    <label>Choisir l'utilisateur</label><br />

    <select name="utilisateur">
     
    <?php
     
    $reponseSalle = $bdd->query('SELECT * FROM mrbs_users ORDER BY name');


     
    while ($donnees = $reponseSalle->fetch(PDO::FETCH_OBJ))
    {
    ?>
               <option value="<?php echo $donnees->id; ?>"> <?php echo $donnees->name; ?></option>
    <?php
    }
     
    ?>
    </select>




  <!-- Filtres par DatePicker -->
<br /> <br />
<script>
  $(function() {

    

    $( "#from" ).datepicker({
      defaultDate: "+1d",
      changeMonth: true,
      numberOfMonths: 1,
      dateFormat : '@',
      onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );
      }
    });
    $( "#to" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 1,
      dateFormat : '@',
      onClose: function( selectedDate ) {
        $( "#from" ).datepicker( "option", "maxDate", selectedDate );
        var currentDate = $( ".selector" ).datepicker( "getDate" );
      }
    });
  });
  </script>
 
<label for="from">Du</label>
<input type="text" id="from" name="from">
<label for="to">Au</label>
<input type="text" id="to" name="to">



<input type='submit' value='Submit'>

 </form>

 <?php
  $dateDebut = $_POST["from"] ;
  $dateFin = $_POST["to"] ;
  echo('La date est : ' . $dateDebut);
  echo($dateFin);
?>

  <!-- Traitement des données -->
 <?php
   //  $_SESSION['nomSalle'] = isset($_POST[''])
  ?>

  </body>
</html>

If anyone could help me.. Thanks in advance !

Aucun commentaire:

Enregistrer un commentaire