We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Implementing Age Verification

Development and Programming

nicholaswyoung's avatar
nicholaswyoung
23 posts
14 years ago
nicholaswyoung's avatar nicholaswyoung
Sounds like you’ll need both an extension and a module. They can both be stored in the same third_party package.

Got it. Is there an example of implementing them both in the same package anywhere?

Also, many thanks for answering all of my questions, Rob. Your help is invaluable.

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
14 years ago
Rob Sanchez's avatar Rob Sanchez

It’s pretty straightforward to have them both in the same package. Let’s say your package is called “age_verifier”. So you’d have a folder called age_verifier that goes in system/expressionengine/third_party/. In there you’d just put your extension and module. So your folder contents would look something like:

ext.age_verifier.php    //class Age_verifier_ext
mod.age_verifier.php    //class Age_verifier
upd.age_verifier.php    //class Age_verifier_upd
mcp.age_verifier.php    //class Age_verifier_mcp

Then, you’d just be sure to install the extension and the module under the Addons tab.

       
nicholaswyoung's avatar
nicholaswyoung
23 posts
14 years ago
nicholaswyoung's avatar nicholaswyoung

After an afternoon (and evening) of tinkering, I think I finally have a handle on the separation between extensions and modules.

Hopefully, this will be my final question.

How do I go about setting up views for my module? And how do I point the form I’ll create for users to input their age at the module action that will parse the form, and check their age? (Is there an example anywhere that I might have missed?)

I have a library that I’ve included to do the actual checking, and provide a list of countries around the world. Hopefully, using this data in my form view will be fairly straightforward.

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
14 years ago
Rob Sanchez's avatar Rob Sanchez

Views are meant for the control panel only. You’d make a views folder in your third_party/your_package_name folder and add your view files there.

If you want to do stuff on the front end, the usual means is by template tags. So let’s say you had a method in your mod file called age_verification_form:

class Age_verifier {
    public function age_verification_form()
    {
        $this->EE =& get_instance();

        $this->EE->load->helper('form');

        $output = $this->EE->functions->form_declaration_data(array(
            'hidden_fields' => array(
                'ACT' => $this->EE->functions->fetch_action_id(__CLASS__, 'age_verification_submit')
            ),
        ));

        $output .= $this->EE->TMPL->tagdata;

        $output .= form_close();

        return $output;
    }

    public function age_verification_submit()
    {
        $this->EE->load->library('your_custom_age_verification_lib');

        $this->EE->your_custom_age_verification_lib->verify($this->EE->input->post('age'));
        //etc.
    }
}

This would correspond with the template tag:

{exp:age_verifier:age_verification_form}
    <input type="text" name="age">
    <input type="submit">
{/exp:age_verifier:age_verification_form}

You’ll notice in the module’s form method I used the function fetch_action_id. This is how the form knows which method to trigger upon submission. It looks up the corresponding “action” in the exp_actions table. Which means, in your installation file (the upd file), you’ll have to be sure to actually install the action into the exp_actions table:

public function install()
{
    $this->EE->db->insert('actions', array('class' => 'Age_verifier', 'method' => 'age_verification_submit'));

    return TRUE;
}

Whew.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.