4

I am developing one publishing website, where authenticated users can write the article. For each article, he sets the age group for which the article is targeted for. Different age group may be "Adult","Pre-teens" and "Everyone". I have used taxonomy to age group.

Now, I want to show warning message to the user, when he goes to any "Adult", classified article page, before loading the content, and get the confirmation from the user that he is 18+ to view this article.

Please suggest how, can I implement this or is there any module that helps me to achieve this.

Thanks for your time.

3
  • have you checked this module drupal.org/project/disclaimer Feb 4, 2013 at 9:47
  • This may help, still will look to it and let you know. Thanks Feb 4, 2013 at 9:52
  • Had gone through it, but I don't think this may help, I want the functionality only for adult content which is decided by one of the taxonomy term value. Feb 4, 2013 at 10:01

2 Answers 2

1

Do you want to implement the age verification for Anonymous users or for logged in users? If you are doing it only for the logged in users maybe a better option would be to just add a birthday field to the user and just verify the age on that, so you won't have to request the age all the time, or only the first time, and then store it in the birthday field.

If not, for the actual confirmation page, you could just use *hook_node_view* and if the user has not confirmed his age for that node, replace the content with the verification form. For the way you can store whether someone has confirmed his age for a node depends, as I've said above, on how you want things to work, for authenticated users, for anonymous users.

0

Theirs so many ways you could implement this, I personally would make a module that uses SESSIONS to remember the users age (saves them being annoyed with confirmations every time they visit the site).

Then in the module create a function that you can call on pages that you want to restrict access to.

Something like

function mymodule_age_verification()
{
  $age = isset($_SESSION['age']) ? $_SESSION['age'] : null;
  if ($age == null) 
  { 
     // print dialog asking for users age
  }
  else if ($age < 18)
  {
    //print error
    exit();
    // dont show this page they aren't old enoguh etc
  }
  else
  { 
    // do nothing they are allowed to go here
  }
}

To prevent the node being displayed based on age you can use something like

function mymodule_node_view()
{
  mymodule_age_verification();
}

Syntax isn't exact. I will provide a more detailed syntax accurate answer if absolutely necessary.

Of course that example is very rough and basic, it would be nice to use AJAX for the age verification entry. But that should be enough to get you started.

3
  • 1
    This doesn't really answer the question? could you please elaborate? Feb 4, 2013 at 9:17
  • I tried to answer his question without doing his work for him.. Feb 4, 2013 at 12:39
  • Still it doesn't answer the question..
    – gagarine
    Jan 17, 2014 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.