Forum

Thread tagged as: Question, Members

Set member tag expire date

Hi, How can I set an expire date for a membership tag at registration? I can set the Tag from the form in the admin but not the expire date.

Shawn North

Shawn North 0 points

  • 5 years ago
<?php perch_member_add_tag('subscriber', '2016-01-23'); ?>

Thanks I have seen that in the docs but how can I set this at registration? For example I have my registration form. I was thinking I could set up hidden form fields that would set a tag and it's expire date when the user registers.

I set the registration form in my template with this..

<?php perch_member_form('register.html'); ?>

Then my registration form here register.html...

<perch:form id="register" method="post" app="perch_members" type="default">

    <div class="form-group">
        <perch:label for="first_name">First name</perch:label>
        <perch:input type="text" id="first_name" required="true" label="First name" class="form-control" />
        <perch:error for="first_name" type="required">Please add your name</perch:error>
    </div>

    <div class="form-group">
        <perch:label for="last_name">Last name</perch:label>
        <perch:input type="text" id="last_name" required="true" label="Last name" class="form-control" />
        <perch:error for="last_name" type="required">Please add your name</perch:error>
    </div>

    <div class="form-group">
        <perch:label for="email">Email</perch:label>
        <perch:input type="email" id="email" required="true" placeholder="you@company.com" class="form-control" helper="PerchMembers_Members::check_email" />
        <perch:error for="email" type="required">Please add your email address</perch:error>
        <perch:error for="email" type="helper">That email address is already in use</perch:error>
    </div>

    <div class="form-group">
        <perch:label for="password">Password</perch:label>
        <perch:input type="password" id="password" required="true" match-with="password2" class="form-control" />
        <perch:error for="password" type="required">Please add a password</perch:error>
        <perch:error for="password" type="match">Passwords do not match</perch:error>
    </div>

    <div class="form-group">
        <perch:label for="password2">Password again</perch:label>
        <perch:input type="password" id="password2" required="true" class="form-control" />
        <perch:error for="password2" type="required">Please repeat your password</perch:error>
    </div>


    <div>
        <perch:input type="submit" value="Register" class="btn btn-primary submit_form" />
    </div>

    <perch:success>
        <p>Thanks!</p>
    </perch:success>

</perch:form>

Where/how would I use this

<?php perch_member_add_tag('subscriber', '2016-01-23'); ?>

so that it is set when the user registers?

Thanks.

Place this code in a block of code which checks a member being logged in. You could add a tag at registration then check for that tag on login and add the new tag at that point.

You can't add a tag with expiration at registration so you'll have to check for another then add if missing.

Does the expire date get reset every time the user logs in? Or does it first check to see if the user has the tag and if he does then skip it?

No. It does not reset. If it already exists nothing will happen. When expired you have to delete to reset.

OK I get it. Thanks!

I'm amusing that if a tag has expired then it treats is as if it is not there, correct? So if I check to see if the tag is not there this should be true. In my test the tag has expired but this check does not work. the result does not display "test tag expired"

<?php if (!perch_member_has_tag('test')) { ?> 
      test tag has expired
<?php } ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What if you log out and back in?

I tried that also and I still get the same result.

Its working now. I did not realize the time is also set on the expire date. It expired today but not till later today. I changed the time in the database to test and all is good. Thanks.