This solution uses only CSS. This is not the best way to do this, since you are limited to a code structure. The% w / w containing the text should be immediately after% w / o, otherwise it will not work.
Your CSS would look like this:
input[type=checkbox]:checked ~ #termoTexto{
display: block;
}
#termoTexto {
display:none;
}
And the HTML like this:
<label>Mostrar termos:</label> <input type="checkbox" id="termos" />
<div id="termoTexto">
Seus termos estarão aqui
</div>
See a working example: link
The recommendation, for you to have more freedom and dynamics in your system would be to use a javascript, for example.
Edited
Doing such a process through PHP is not the correct one, because for this you would have to:
- Have a table in the database for every person who accesses the system, whether it is registered or visitor (I would say it is impossible);
- Change the data of this table, if the user exits the page without clicking on the
div
, this value will remain as input checkbox
(or as it left before leaving the page);
- To check if it clicked, you would need to query the database, which can be "slow" (compared to other methods);
In summary, with PHP (at least I do not know) there is no way to make this system you're looking for.
Edited 2:
I made a very simple example using jQuery only. In this example you have more freedom because it does not have to be in an order. You can have the elements anywhere on your page.
But for this you will need to insert jQuery into your project. If you do not know, take a look at this link , there are others out there, just search.
Basic example of checkbox
used:
$('.termos').click(function() {
$('.meuTermo').toggle(1000);
});
This function creates a toggle , that is, with each click it displays (if it is hidden) or hidden (if it is visible), everything automatic, you do not have to do anything else, whether or not it is visible in the initial state. In your case it will be hidden, so we use CSS:
.meuTermo {
display:none; /* mantem a div escondida no inicio da página */
}
Example working with true
: link
Note: Of course, this is a basic example. If you want something more robust, more secure, this would not be the best method, but with that you have the general idea and would already have where to start.