There is a form for adding equipment, it has a text field where you can enter text, and it will be transferred to the database, and next you have to put a checkbox, so that you can either enter a value in the field or transmit a “fixed” value by clicking on the checkbox.

* Example (consider entering the IP address of the device): *

  1. In the field you can enter the IP address (if any)
  2. or click on the checkbox (if the device does not have an IP), when you click on CheckPoint, the phrase "Not available" is sent to the database

And most importantly, if we enter text into a field, one value is passed, and if we set a checkbox, another value is passed, but in ONE column

Question: how to do?

    2 answers 2

    Javascript in your hands. By clicking on the checkbox, we write it in the text field "Does not have" and the disable field. You can memorize the value that was in the text field before clicking, and by the second click on the checkbox, write the old value in the field. Another option - on the submit form, we hang up the handler, which checks whether the checkbox was clicked, and if so, instead of entering the value in the text field, it substitutes "Does not have".

      <form action="#" method="post"> <input type="text" name="ip"> <input type="checkbox" name="ip_check">Нет IP <br/> <input type="submit"> </form> <?php isset($_POST['ip_check'])?$ip="Не имеет":$ip=$_POST['ip']; echo $ip; ?> 

      clearly show.

      in order for the input form to become disabled, you need to add another javascript code.