Display / Hide "Terms of Use" by clicking checkbox

2

How do I checkmark a site's content when I check it?

For example, I want to make a terms of use system, whereby clicking on "I accept the terms" will release the button to proceed with the content.

I made the following form, I created a column in the database with the name of "terms", "size 11" of type "INT" and then I made a query using sessions as follows:

 if($_SESSION['termos'] == 1){
    //ele exibe o conteudo direto sem exibir os termos de uso
} else {
    //exibe os termos de uso com a checkbox e ao selecionar a checkbox é liberado o botão para prosseguir. Ao clicar no botão ele altera o campo "termos" do usuario logado para 1 e assim não exibe mais os termos
}
    
asked by anonymous 14.11.2015 / 22:36

1 answer

5

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.

    
14.11.2015 / 23:09