Essentially what you’re looking for is to submit the form when someone clicks on checkbox instead of using links.
For this purpose, you can add an attribute onChange to the element checkbox that will run Javascript responsible for triggering the submission of the form:
<form action='_cal.php' method="get">
<input type="checkbox" name="change" value="1" onChange="this.form.submit()"> Alterar
</form>
Note that I also changed the address of the form because by submitting the same route GET, will be added to the URL a string in format NVP of the fields present in it.
Your checkbox is called change and with the value 1, in combination with the URL _cal.php where the form will submit the information, you will get:
_cal.php?change=1
Additional note:
To check 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 numerical representation 1 or 0.
See demonstration in Ideone.
How the form is being sent?
– Bacco
By GET. I want to send to the same page.
– akm
So just change the
value="change"forvalue="1"on the line ofinputand take out the?change=1of the line ofform.– Bacco
Note that these variable change questions do not make much sense, since, with the default architecture, it is not possible to change anything that is done in PHP through an HTML or JS/Ajax. What is happening is the sending of new information. When an HTML or JS is running, the PHP that generated them has already been processed and is already "running". You will always be calling a new PHP execution, be it the same script or another.
– Bacco
Try by AJAX , making an asynchronous request , of a researcher on this subject , will be of great use
– Bruno Pantaleão
It would be possible for you to rewrite your question in more detail and stating exactly what you want to do?
– Kazzkiq