How to pass the value in a toggle button in bootstrap

I have this toggle button code. How to pass the values from this toggle button by the POST method..

<div class="form-group col-md-4">
 <label>Sold Out</label>
 <div> 
   <button data-toggle="collapse">YES</button>
   <button data-toggle="collapse">NO</button>
 </div>
</div>

Answers 1

  • Try this

    <?php
        if (isset($_POST['yesBtn'])) {
            echo "<p>".$_POST['yesBtn']."</p>";
        }
        if (isset($_POST['noBtn'])) {
            echo "<p>".$_POST['noBtn']."</p>";
        }
    ?>
    <form action="somefile.php" method="POST">
        <div class="form-group col-md-4">
            <label>Sold Out</label>
            <div> 
                <button data-toggle="collapse" name="yesBtn" value="YES">YES </button>
                <button data-toggle="collapse" name="noBtn" value="NO">NO</button>
            </div>
        </div>
    </form>
    

    Or this

    <?php
        if (isset($_POST['Btn'])) {
            echo "<p>".$_POST['Btn']."</p>";
        }
    ?>
    <form action="somefile.php" method="POST">
        <div class="form-group col-md-4">
            <label>Sold Out</label>
            <div> 
                <button data-toggle="collapse" name="btn" value="YES">YES </button>
                <button data-toggle="collapse" name="btn" value="NO">NO</button>
            </div>
        </div>
    </form>
    

Related Articles