Show/Hide "Terms of Use" by clicking checkbox

Asked

Viewed 1,892 times

2

How do I, when marking a checkbox, release content from the site?

For example, I want to make a system of terms of use, where by clicking "I accept the terms" it releases the button to proceed with the content.

I did as follows, created a column in the database with the name of "terms", "size 11" 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
}
  • 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.

  • 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 }

  • Edit your question with these details.

  • 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.

  • 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?

1 answer

5


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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.