dimanche 22 novembre 2015

php checkboxes retain values from page to page

I have form page calling a function that pulls 2 random names from a mysql database (called by php function pairsim()). I want to create a group of checkboxes that will create conditions that I can use to limit to mysql pulls. These conditions then need to live on until the user changes the configurations (update button below).

I am hoping to create an array of checked values to use as a condition until the user updates his configurations again. Unfortunately, I can't get the array to persist while going page to page. I am also having trouble creating an array to pass back into the pairsim(). Forgive my ignorance, is there anyway to accomplish what I am trying to do?

select_checkbox.php:

<?php 
session_start();

$_SESSION['G'] = isset($_POST['pG']) ? 1 : 0 ;
$_SESSION['D'] = isset($_POST['pD']) ? 1 : 0 ;
$_SESSION['W'] = isset($_POST['pW']) ? 1 : 0 ;
$_SESSION['C'] = isset($_POST['pC']) ? 1 : 0 ;

?>

<button class="btn btn-success" type="button" data-toggle="collapse" data-    target="#collapselimit" aria-expanded="false" aria-controls="collapselimit">
      Limit Names
    </button>
<div class="collapse container-fluid" id="collapselimit">

<form role="form" method="post" action=<?php pairsim() ; ?>>
<div class="panel panel-default">
    <div class="panel-body">


        <p><b>Position Limited:</b><br></p>
        <!--create array with checked values to include to mysql function-->
            <label class='checkbox-inline'><input type='checkbox' name='positionsel[]' value='pG' checked>Goalies</label>
            <label class='checkbox-inline'><input type='checkbox' name='positionsel[]' value='pD' checked>Defensemen</label>
            <label class='checkbox-inline'><input type='checkbox' name='positionsel[]' value='pW' checked>Wingers</label>
            <label class='checkbox-inline'><input type='checkbox' name='positionsel[]' value='pC' checked>Centers</label>

        <div>
        <!--locks in checkbox configuratons-->
        <input type="submit" class="btn btn-success btn-lg" value="Update"/>
        <!--script below to check/uncheck all-->
        <input type="button" class="btn btn-default btn-lg" id="CheckAll" value="Check All" />
        <input type="button" class="btn btn-default btn-lg" id="UncheckAll" value="Clear All" />
        </div>  
    </form>
        </div>
</div>




Aucun commentaire:

Enregistrer un commentaire