This solution uses only CSS. It’s not the best way to do this, as you are limited to a code structure. A div
which contains the text must be immediately after the input checkbox
, otherwise it will not work.
Your CSS would look like this:
input[type=checkbox]:checked ~ #termoTexto{
display: block;
}
#termoTexto {
display:none;
}
And HTML like this:
<label>Mostrar termos:</label> <input type="checkbox" id="termos" />
<div id="termoTexto">
Seus termos estarão aqui
</div>
See a functional example: http://jsfiddle.net/wy0no7f5/1/
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 right one, because for that you would have to:
- Have a table in the bank for each person who access the system, whether registered or visitor (I would say it is impossible);
- Change the data from this table if the user leaves the page without clicking again on
checkbox
, this value will remain as true
(or how he left it before he left the page);
- To check if it clicked, you would need to make a database query, which can be "slow" (compared to other methods);
In short, with PHP (at least I don’t know) there is no way to make this system that you seek.
Edited 2:
I made a very simple example using only jQuery. In this example you have more freedom because it doesn’t need to be in an order. You can have the elements anywhere on your page.
But for this you will need to insert jQuery in your project. In case you do not know, take a look at this link, there are others out there, just search.
Basic example of jQuery
used:
$('.termos').click(function() {
$('.meuTermo').toggle(1000);
});
This function creates a toggle, that is, in each click it displays (if it is hidden) or hidden (if it is visible), all automatic, do not need to do anything else, except to define whether it will be visible or not 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 jQuery
: http://jsfiddle.net/q71qne54/
Note: Of course, this is a basic example. If you want something more robust, with more security, this would not be the best method, but with this you have the general idea and would already have where to start.
Alfredo, for this you will need to use a javascript, or another language that is not only html. Or some css style that displays this with a :checked. But in order to help you, you need to provide your code, or a portion of it, to let us know what you have, what you have tried and identify what may be going on.
– celsomtrindade
i did as follows, I created a column in the database with the size 11 term name of type INT and then made a query using sessions as follows if($_SESSION['terms'] == 1){ it displays the direct content without displaying the terms of use }Else { displays the terms of use with the checkbox ai when selecting the checkbox it releases the button to proceed and when clicking the button it changes the user’s logged in terms field to 1 and thus no longer displays the terms }
– Alfredo Lima
Edit your question with these details.
– celsomtrindade
Alfredo, this approach your not the best. Post yourself code and explain better, that surely you will have a satisfactory answer. In my view, you just need to create a field to check whether or not the terms have been accepted. That is, if accepting the terms is something required.
– Randrade
With
PHP
is not the best method to do this because it is not "dynamic". Are you using something in Javascript? Like jQuery, for example?– celsomtrindade