Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ashostak

    (@ashostak)

    I believe to be almost there —

    (1) I am specifying a “cookie” as the “data-message” attribute of each option, for instance with Quebec:

    [
      'age' => false,
      'name' => 'Quebec',
      'cookie' => 'qb'
    ]

    Which gets included in each option as so:
    $fields .= '<option id="ag-province" <strong>data-message="'. $province['cookie'] .'"</strong> value="'. base64_encode(base64_encode($province['age'])) .'">'. $province['name'] .'</option>'

    (2) Then I am creating a cookie called “age_gate_province” with the value based on the selected province field:

    if (e.target.options[e.target.selectedIndex].dataset.message) {	
      let cookie = e.target.options[e.target.selectedIndex].dataset.message;
      createCookie('age_gate_province', cookie, 30);
    }

    (A sample function of the createCookie function can be found here: https://www.quirksmode.org/js/cookies.html)

    (3) Then I am reading the set cookie in the PHP templates to determine what content gets served up:

    @if(isset($_COOKIE['age_gate_province']))
       @if($_COOKIE['age_gate_province'] === 'qb')
         ...
       @endif
    @endif

    (4) Then under Age Gate > Restrictions, I am setting the option for “Redirect failures” to go to a general template that serves up different templates based on the province cookie.

    The only thing I need help figuring out is how to get it to honour the ‘age’ value being set to ‘false’ (rather than a specific age value) to consider this to be an unsuccessful attempt and send it to this Sorry page?

    • This reply was modified 6 years, 4 months ago by ashostak.
    • This reply was modified 6 years, 4 months ago by ashostak.
    Thread Starter ashostak

    (@ashostak)

    This worked perfectly, thank you very much Phil.
    Do you have a donation link setup as I’d love to make a contribution for all your work on this.

    All the best,

    Art

Viewing 2 replies - 1 through 2 (of 2 total)