Only select one form switcher with PHP

Very simple question ...

How can I enable the selection of one option in the switch list?

<form action="process_repair.php" method="POST"> <label for "repair_complete">Repair complete</label> <input type="radio" name="Yes" value="true"> <input type="radio" name="No" value="false"> </form> 

When this code works, you can select both radio buttons, but I would like them to interact, so you can only choose one or the other.

Any help is much appreciated! :)

+4
source share
2 answers

Give them the same name.

 <form action="process_repair.php" method="POST"> Repair complete <input type="radio" name="complete" value="true" id="complete_yes" /> <label for="complete_yes">Yes</label> <input type="radio" name="complete" value="false" id="complete_no" /> <label for="complete_no">No</label> </form> 

Labels must have a for attribute directing to the corresponding id input.

+23
source

Each entry must have the same "name"

+2
source

Source: https://habr.com/ru/post/1286175/


All Articles