Forum

Thread tagged as: Question, Suggestions, Discussion

Applying Member Tags and displaying different content for each tag

I want to display different content depending upon what member tag is assigned to a member.

When they hit my application page for the first time I want the tag 'application-started' to be added to that member. On that page is a 3rd party form. Once this form has been submitted and the entry has been received - the system admin will then go and remove the tag 'application-started' from that persons account and add 'application-received'. Now when that member visits the application page they should no longer see the application form and instead should see whatever is in perch_content('Application Received');

So I only want the content for that member tag to be displayed and all other content for other tags to be hidden.

Now the way I currently have it configured below isn't working and it just keeps adding the Member Tag 'application-started' alongside any other tag e.g. 'application-received' and keeps showing them the application form. I'm guessing I can't have 'perch_member_add_tag('application-started');' under else.

Any help would be very much appreciated.

Thanks

<?php
        if (perch_member_has_tag('everything-complete')) {
          perch_content('Everything Complete');
        } if (perch_member_has_tag('payment-pending')) {
          perch_content('Payment Pending');
        } if (perch_member_has_tag('application-accepted')) {
          perch_content('Application Accepted');
        } if (perch_member_has_tag('application-rejected')) {
          perch_content('Application Rejected');
        } if (perch_member_has_tag("application-pending")) {
          perch_content('Application Pending');
        } if (perch_member_has_tag('application-received')) {
          perch_content('Application Received');
        } else {
          perch_content('Application Form');
          perch_member_add_tag('application-started');
        }
      ?>
Richy Thomas

Richy Thomas 0 points

  • 4 years ago

just add the different tags as each step is completed then test for the tag. Might be best if you set the tags to expire rather then removing them... because if the member has not logged out then sometimes the tags may be persistent and will cause you headaches in the future.

I don't really want to set expiry dates. Each member will only likely be in each stage for a few days.

The problem I'm having .. is that even if I remove the tag 'application-started' and add one of the others 'application-received' when I go back to the page 'application.php' that displays the content .. it keeps re-adding the initial tag 'application-started' and shows me the content that's in my else bit of the statement .. when I'd like it to not show this and to show the perch content that I've added for the tag 'application-started'

Hope that makes sense? I'm guessing there's an issue with my if statements

Drew McLellan

Drew McLellan 2638 points
Perch Support

If they're moving through a process you could just use the last-matching case.

$steps = [
    [ 'application-received' => 'Application Received' ],
    [ 'application-pending' => 'Application Pending' ],
    [ 'application-rejected' => 'Application Rejected' ],
    [ 'application-accepted' => 'Application Accepted' ],
    [ 'payment-pending' => 'Payment Pending' ],
    [ 'everything-complete' => 'Everything Complete' ],
];

$chosen_region = 'Application Form';

foreach($steps as $tag => $region) {
    if (perch_member_has_tag($tag)) $chosen_region = $region;
}

perch_content($chosen_region);

Ok I've implemented your solution.

Issue I'm having now is that even though I have 6 Perch regions on the page. It's only letting me define and add content for one in Perch Admin. So when visit the page and then view the [age in Perch admin. It's only picking up one region and allowing me to select one template. So say for instance I select 'Application Form' then my members are seeing that and only that

How can I get access to all of these regions and add content to them. At the moment. No matter what tags are added to a members account. They are only ever seeing the application form.

<?php include('../something/runtime.php'); ?>
<?php perch_layout('global.header'); ?>
<section class="content no-header">
  <div class="container">
    <div class="row">
      <?php
        $steps = [
        [ 'application-received' => 'Application Received' ],
        [ 'application-pending' => 'Application Pending' ],
        [ 'application-rejected' => 'Application Rejected' ],
        [ 'application-accepted' => 'Application Accepted' ],
        [ 'payment-pending' => 'Payment Pending' ],
        [ 'everything-complete' => 'Everything Complete' ],
        ];

        $chosen_region = 'Application Form';

        foreach($steps as $tag => $region) {
        if (perch_member_has_tag($tag)) $chosen_region = $region;
        }

        perch_content($chosen_region);
      ?>
    </div>
  </div>
</section>

<?php perch_layout('global.footer'); ?>
</body>
</html>

You should use perch_content_create() to create the regions.

https://docs.grabaperch.com/functions/content/perch-content-create/

Drew McLellan

Drew McLellan 2638 points
Perch Support

Robert it right. Add it to the for loop.

foreach($steps as $tag => $region) {
if (perch_member_has_tag($tag)) $chosen_region = $region;
perch_content_create($region, ['options']);
// or add the options array() to the $steps array and use
// perch_content_create($region[0], $region['options']);
}

UNTESTED... sorry

I didn't think of doing that guys. I took the long road - Only just sen the two messages above

What I did below worked anyway. It allowed me to create the regions and add content.

I'm logged in as a member that has the Member Tag 'application received' on their account. But when I visit the page I'm still seeing the application form?

No matter what tag I have assigned. I am only ever seeing the Application Form???

<?php include('../something/runtime.php'); ?>
<?php perch_content_create('Application Received', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-application-received.html',
  ));
?>
<?php perch_content_create('Application Pending', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-application-pending.html',
  ));
?>
<?php perch_content_create('Application Rejected', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-application-rejected.html',
  ));
?>
<?php perch_content_create('Application Accepted', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-application-accepted.html',
  ));
?>
<?php perch_content_create('Payment Pending', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-payment-pending.html',
  ));
?>
<?php perch_content_create('Everything Complete', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-everything-complete.html',
  ));
?>
<?php perch_content_create('Application Form', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-form.html',
  ));
?>
<?php perch_layout('global.header'); ?>
<section class="content no-header">
  <div class="container">
    <div class="row">
      <?php
        $steps = [
        [ 'application-received' => 'Application Received' ],
        [ 'application-pending' => 'Application Pending' ],
        [ 'application-rejected' => 'Application Rejected' ],
        [ 'application-accepted' => 'Application Accepted' ],
        [ 'payment-pending' => 'Payment Pending' ],
        [ 'everything-complete' => 'Everything Complete' ],
        ];

        $chosen_region = 'Application Form';

        foreach($steps as $tag => $region) {
          if (perch_member_has_tag($tag)) $chosen_region = $region;
        }

        perch_content($chosen_region);
      ?>
    </div>
  </div>
</section>

<?php perch_layout('global.footer'); ?>
</body>
</html>

this line in your code is the reason $chosen_region = 'Application Form';

I kinda guessed that. But I thought that If I took it out then no-one would see the Application form. I only want the application Form Region to show if no tags are assigned

then add else statement to if (perch_member_has_tag($tag))

Thanks Robert. I'm almost there I know. But getting an unexpected else error now

<?php include('../something/runtime.php'); ?>
<?php perch_content_create('Application Received', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-application-received.html',
  ));
?>
<?php perch_content_create('Application Pending', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-application-pending.html',
  ));
?>
<?php perch_content_create('Application Rejected', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-application-rejected.html',
  ));
?>
<?php perch_content_create('Application Accepted', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-application-accepted.html',
  ));
?>
<?php perch_content_create('Payment Pending', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-payment-pending.html',
  ));
?>
<?php perch_content_create('Everything Complete', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-message-everything-complete.html',
  ));
?>
<?php perch_content_create('Application Form', array(
    'edit-mode' => 'listdetail',
    'template' => '/application/application-form.html',
  ));
?>
<?php perch_layout('global.header'); ?>
<section class="content no-header">
  <div class="container">
    <div class="row">
      <?php
        $steps = [
        [ 'application-received' => 'Application Received' ],
        [ 'application-pending' => 'Application Pending' ],
        [ 'application-rejected' => 'Application Rejected' ],
        [ 'application-accepted' => 'Application Accepted' ],
        [ 'payment-pending' => 'Payment Pending' ],
        [ 'everything-complete' => 'Everything Complete' ],
        ];

        foreach($steps as $tag => $region) {
          if (perch_member_has_tag($tag)) $chosen_region = $region;
        } else {
          $chosen_region = 'Application Form';
        }

        perch_content($chosen_region);
      ?>
    </div>
  </div>
</section>

<?php perch_layout('global.footer'); ?>
</body>
</html>

I thought about just having the application form as a step too and adding a member tag when someone registers and initially becomes a member.

But now I'm getting a message rendering to my page saying:

You must pass in a name for the content. e.g. <?php perch_content('Phone number'); ?>

<?php include('../something/runtime.php'); ?>
<?php perch_content_create('Application Received', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_application_received.html',
  ));
?>
<?php perch_content_create('Application Pending', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_application_pending.html',
  ));
?>
<?php perch_content_create('Application Rejected', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_application_rejected.html',
  ));
?>
<?php perch_content_create('Application Accepted', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_application_accepted.html',
  ));
?>
<?php perch_content_create('Payment Pending', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_payment_pending.html',
  ));
?>
<?php perch_content_create('Everything Complete', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_everything_complete.html',
  ));
?>
<?php perch_content_create('Application Form', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_form.html',
  ));
?>
<?php perch_layout('global.header'); ?>
<section class="content no-header">
  <div class="container">
    <div class="row">
      <?php
        $steps = [
        [ 'application-new' => 'Application Form' ],
        [ 'application-received' => 'Application Received' ],
        [ 'application-pending' => 'Application Pending' ],
        [ 'application-rejected' => 'Application Rejected' ],
        [ 'application-accepted' => 'Application Accepted' ],
        [ 'payment-pending' => 'Payment Pending' ],
        [ 'everything-complete' => 'Everything Complete' ],
        ];

        foreach($steps as $tag => $region) {
          if (perch_member_has_tag($tag)) $chosen_region = $region;
        }

        perch_content($chosen_region);
      ?>
    </div>
  </div>
</section>

<?php perch_layout('global.footer'); ?>
</body>
</html>

Richy Thomas said:

I thought about just having the application form as a step too and adding a member tag when someone registers and initially becomes a member.

But now I'm getting a message rendering to my page saying:

You must pass in a name for the content. e.g. <?php perch_content('Phone number'); ?>

<?php include('../something/runtime.php'); ?>
<?php perch_content_create('Application Received', array(
   'edit-mode' => 'listdetail',
   'template' => 'application_message_application_received.html',
 ));
?>
<?php perch_content_create('Application Pending', array(
   'edit-mode' => 'listdetail',
   'template' => 'application_message_application_pending.html',
 ));
?>
<?php perch_content_create('Application Rejected', array(
   'edit-mode' => 'listdetail',
   'template' => 'application_message_application_rejected.html',
 ));
?>
<?php perch_content_create('Application Accepted', array(
   'edit-mode' => 'listdetail',
   'template' => 'application_message_application_accepted.html',
 ));
?>
<?php perch_content_create('Payment Pending', array(
   'edit-mode' => 'listdetail',
   'template' => 'application_message_payment_pending.html',
 ));
?>
<?php perch_content_create('Everything Complete', array(
   'edit-mode' => 'listdetail',
   'template' => 'application_message_everything_complete.html',
 ));
?>
<?php perch_content_create('Application Form', array(
   'edit-mode' => 'listdetail',
   'template' => 'application_form.html',
 ));
?>
<?php perch_layout('global.header'); ?>
<section class="content no-header">
 <div class="container">
   <div class="row">
     <?php
       $steps = [
       [ 'application-new' => 'Application Form' ],
       [ 'application-received' => 'Application Received' ],
       [ 'application-pending' => 'Application Pending' ],
       [ 'application-rejected' => 'Application Rejected' ],
       [ 'application-accepted' => 'Application Accepted' ],
       [ 'payment-pending' => 'Payment Pending' ],
       [ 'everything-complete' => 'Everything Complete' ],
       ];

       foreach($steps as $tag => $region) {
         if (perch_member_has_tag($tag)) $chosen_region = $region;
       }

       perch_content($chosen_region);
     ?>
   </div>
 </div>
</section>

<?php perch_layout('global.footer'); ?>
</body>
</html>

if your going to do it this way then you need to add the tag application-new before the $steps otherwise your not going to get a region name returned from foreach

Yes - this doesn't seem to be working :( I don't particularly want to do it this way but I couldn't get the else statement to work. Was giving me an error. I'm proper confusing myself now - and I know this is relatively simple stuff

make sure your clearing the cookies on your test member before you test code changes... either by removing the p_m cookie in the browser or perch_member_logout() and then log member back in...

Otherwise you may be fighting the session cookies... and throwing away working code.

Ahh - Didn't know this.

Does the syntax on this look correct to you:

foreach($steps as $tag => $region) {
if (perch_member_has_tag($tag)) $chosen_region = $region;
} else {
$chosen_region = 'Application Form';
}

Richy Thomas said:

Ahh - Didn't know this.

Does the syntax on this look correct to you:

foreach($steps as $tag => $region) {
if (perch_member_has_tag($tag)) $chosen_region = $region;
} else {
$chosen_region = 'Application Form';
}
foreach($steps as $tag => $region) {
$chosen_region = 'Application Form';
if (perch_member_has_tag($tag)) $chosen_region = $region;
}

is another way to do it...

It will still only slow my Application Form regardless of what tags are attached to the member :/

<?php include('../something/runtime.php'); ?>
<?php perch_content_create('Application Received', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_application_received.html',
  ));
?>
<?php perch_content_create('Application Pending', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_application_pending.html',
  ));
?>
<?php perch_content_create('Application Rejected', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_application_rejected.html',
  ));
?>
<?php perch_content_create('Application Accepted', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_application_accepted.html',
  ));
?>
<?php perch_content_create('Payment Pending', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_payment_pending.html',
  ));
?>
<?php perch_content_create('Everything Complete', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_message_everything_complete.html',
  ));
?>
<?php perch_content_create('Application Form', array(
    'edit-mode' => 'listdetail',
    'template' => 'application_form.html',
  ));
?>
<?php perch_layout('global.header'); ?>
<section class="content no-header">
  <div class="container">
    <div class="row">
      <?php
        $steps = [
        [ 'application-received' => 'Application Received' ],
        [ 'application-pending' => 'Application Pending' ],
        [ 'application-rejected' => 'Application Rejected' ],
        [ 'application-accepted' => 'Application Accepted' ],
        [ 'payment-pending' => 'Payment Pending' ],
        [ 'everything-complete' => 'Everything Complete' ],
        ];

        foreach($steps as $tag => $region) {
          $chosen_region = 'Application Form';
        if (perch_member_has_tag($tag)) $chosen_region = $region;
          }

        perch_content($chosen_region);
      ?>
    </div>
  </div>
</section>

<?php perch_layout('global.footer'); ?>
</body>
</html>

you need to make sure your assigning new tags at the top of your code, if you assign new tags as admin to a signed in user those tags will not effect the user till they logout and login again because the session has already been written.

This is why its so important to make sure you delete the p_m cookie when testing your code on a member

it will force a new session