If you’re not really serious about this, you can do it with
JavaScript. If there are legal ramifications if someone sees your site
(gasp!) about beer (egads!) before their age of majority (horrors!)
then you can do more serious things like server-side validation to
keep the young’uns away.
Here’s one stab at the JavaScript way. It’s cheap and cheerful, and
won’t annoy people except once. Anyone with half a brain can just
disable JS and see your site anyway – but you actually want this,
because you don’t want to keep Google out of your business.
In your Master Page, go to the Page / HTML Markup dialog, and move to
the Before /head section using the picker in the bottom-left corner.
Enter the following:
<script type="text/javascript">
if(!(document.cookie && document.cookie.match(/old_enough/))){
window.location.href = 'age_form.html';
}
</script>
So what this does is look up the document cookie with JavaScript, see
if you’ve already set a cookie for this user (well, browser anyway).
If not, then you redirect to a new page called age_form.html.
Next step is to create this age_form page. But don’t just make a page
based on the same master you just modified – you’ll end up with the
tricky script above on that page as well. Make a new Master page, and
base your new form page on that. If you choose to make the filename
something other than age_form.html, be sure to modify the script above
to match. Note that you can have completely different page Title and
page Filename, and only the latter will matter in this case.
On your form page, you only need to have the form field and any
instructions required. It’s very important that you don’t include any
navigation links on this page at all, because you don’t want it to end
up in a search result anywhere. Doing so would break the simple system
for returning the visitor to their original page after they confirm
their age.
I’m assuming that you used the third tab from the left in the
Inspector to name your birth year field ‘birthyear’ (without the
quotes). You’ll need to add instructions for your users that they must
enter the full YYYY year.
In the Page Markup dialog, you’ll add a bit more code this time, and
to a different part of the page – Before /body:
<script type="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
var checkform = document.forms[0];
var birthdate = checkform.birthyear;
checkform.onsubmit = function(evt){
evt.preventDefault();
var d = new Date();
var y = parseInt(birthyear.value,10);
if(y > 1900) //they entered something date-like
d.setFullYear(y);
var d2 = new Date();
d2.setFullYear(d2.getFullYear() - 21);
if(d <= d2){ //they are 21 or older
createCookie('old_enough','true',365); //one year
var next = document.referrer || 'index.html';
document.location.href = next;
}else{
alert('Sorry, this Web site is only for persons old enough to
drink!');
}
return false;
};
</script>
As long as you have named your form field correctly, this should just
work out of the box. If you have questions or can’t seem to get it
working, please upload it somewhere that we can see it (on your own
server, perhaps) and post a link here where we can try it out.
Walter
On Jun 7, 2011, at 8:47 PM, Brent wrote:
Hey guys!
I’m a newb. I am building a website for a brewery.
And I need to build a homepage that ask for birthdate in order for
someone to continue on to the website, otherwise they will be kicked
off.
Can someone help me on this?
actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options