Forum

Thread tagged as: Problem, Members

Member tag updated only after logout

Hello,

I am trying to set up a form for members that each member can fill out only once. To do this, I am redirecting members after the successful form submission to a page where the member gets a 'submitted' tag:

<?php
  perch_member_add_tag('submitted');
  echo '<p>We received your form. Thanks!</p>';
?>

Then, on the member page I tried to display the form only if the member does not have the 'submitted' tag:

<?php 
if (perch_member_logged_in()) {
    echo '<h1>Welcome back!</h1>';
    if (perch_member_has_tag('submitted')) {
        echo '<p>You already submitted your form.</p>';
    } else {
        echo '<p>Please fill in the following form:</p>';
        perch_form('contact.html');
    };
} else {
    echo '<h1>You are not logged in.</h1>';
}
?>

The problem is that if the member submits the form, then returns to the member page, the form still shows up as if the member didn't get the tag (which shows up in the admin though). If the member logs out and in again, the tag detection works well and the form is not shown again.

Please let me know how can I make the tag detection work without having to log out the member.

Thanks a lot in advance!

Laszlo

Laszlo Grama

Laszlo Grama 0 points

  • 5 years ago

You need to make sure the tag is added to the member before anything is output to the browser and before headers are sent.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I believe this has changed in the current version, but I'll check.

Dear Robert, dear Drew,

Sorry for getting back to you with such a delay: it was only now that I had to get back to the problem.

Robert's suggestion worked well. I added the tag before loading the page headers.

Thank you very much!

Here's the code, just in case someone's interested:

<?php include('../perch/runtime.php'); ?>

<?php 
    if (perch_member_logged_in()) {
        perch_member_add_tag('submitted');
    }
?>

<?php perch_layout('header'); ?>