Essentially what you are looking for is to submit the form when someone clicks the checkbox
instead of using links.
For this purpose, you can add a onChange
attribute to the checkbox
element that will execute JavaScript responsible for triggering the form submission:
<form action='_cal.php' method="get">
<input type="checkbox" name="change" value="1" onChange="this.form.submit()"> Alterar
</form>
Notice that I also changed the form's address because when submitting the same via GET
, a string in the format NVP of the fields present in it.
Your checkbox
is called change
and with the 1
value, in combination with the _cal.php
URL where the form will submit the information, you will get:
_cal.php?change=1
Additional note:
To check for the presence of the URL variable change
, you can simplify your code to:
$change = (int)isset($_GET['change']);
To explain, the function isset()
returns a boolean TRUE
or FALSE
. Preceded by (int)
will pass the boolean to its numeric representation 1
or 0
.
View demo on Ideone .