mercredi 27 mai 2020

Run two checkboxes when both are selected in php

I have a form that has two checkboxes.

<form action="test.php" method="post">
    <input type="checkbox" name="check1" value="check1">
    <label for="check1">Checkbox 1</label><br>

    <input type="checkbox" name="check2" value="check2">
    <label for="check2">Checkbox 2</label><br>
</form>

When the checkbox 1 is selected, its value is displayed on the test.php page, and when the second checkbox is selected, another value is displayed.

<?php

if (@$_POST['check1']) {
    echo "oh you clicked on Checkbox 1";

} elseif (@$_POST['check2']) {
    echo "oh you clicked on Checkbox 2";    
}
?>

In this method, which uses if statements, the program works. But when both checkboxes are selected, the value of both is expected to be displayed, which is impossible with if statements.

I want an algorithm or code that shows the values of their pair if both of them are selected.




Aucun commentaire:

Enregistrer un commentaire