How to get the values of an Bootstrap Toggle Button?

Viewed 1419

How can I get the value '0' and '1' out of my toggle button? The value one or zero will be sent to the order.inc.php page when the button is pressed.

Order.php page:

<div class="checkbox">
    <form method="post" action="includes/edit-orderstatus.inc.php">
        <td><input type="checkbox" checked data-toggle="toggle" data-off="Shipped" data-on="Pending" data-offstyle="success" id="statusOrder" name="statusOrder" data-onstyle="danger" value="1"></td>
        <input type="hidden" name="orderID" id="orderID" value="<?php echo ($datas[$i]['ID']);?>">
        <td><button class="btn btn-dark" type="submit" name="orderstatus-submit">Submit</button></td>
    </form>
</div> 

Order.inc.php page

<?php
if(isset($_POST['orderstatus-submit'])){

        require('../php/connection.php');
        $toogleButtonValue = (int)(isset($_POST['statusOrder']) && $_POST['statusOrder'] == 1);

        echo $toogleButtonValue;

}

1 Answers

You must set value attribute of checkbox, i.e. value="1".

It returns 1 if any value was sent or 0 otherwise.

$toogleButtonValue = (int)(isset($_POST['statusOrder']) && $_POST['statusOrder'] == 1)
Related