Show message once on first login

2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 23, 2016   (RSS)

By gregThomas - June 23, 2016

Hey superhappybunnycat,

You could add a checkbox field to the website membership accounts section called something like "Shown Message" and ensure that it is set as unchecked by default. Then ensure that a value of zero is added for it when an account is created on the sign up page:

  $colsToValues = array();
  $colsToValues['createdDate=']     = 'NOW()';
  $colsToValues['updatedDate=']     = 'NOW()';
  $colsToValues['createdByUserNum'] = 0;
  $colsToValues['updatedByUserNum'] = 0;

  // fields defined by form:
  //$colsToValues['agree_tos']      = $_REQUEST['agree_tos'];
  $colsToValues['fullname']         = $_REQUEST['fullname'];
  $colsToValues['email']            = $_REQUEST['email'];
  $colsToValues['username']         = coalesce( @$_REQUEST['username'], $_REQUEST['email'] ); // email is saved as username if usernames not supported
  $colsToValues['password']         = $passwordHash;
  $colsToValues['shown_message']    = '0';
  // ... add more form fields here by copying the above line!
  $userNum = mysql_insert(accountsTable(), $colsToValues, true);

Then you can use the following if statement to check if the user has seen the message, display it, and update their account once it's been displayed:

<?php if($CURRENT_USER && !$CURRENT_USER['shown_message']): ?>
  <p>A message</p>
 <!-- update the users account so we know we've shown them the message --> 
 <?php mysql_update(accountsTable(), $CURRENT_USER['num'], null, array('shown_message' => '1')); ?>
<?php endif; ?>

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com