errorsAndAlerts and calling dynamic data for the alert ref: membership plugin

12 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: July 6, 2017   (RSS)

By Twocans - June 15, 2017

Hi yea,
I want to have dynamic data for my actual alerts. 

I go to the membership plugin dir and open the associated page. I then navigate to the error checking code as so

// error checking

if (!@$_REQUEST['username']) { alert("Please enter a username!<br/>\n"); }
else if (!@$_REQUEST['password']) { alert("Please enter a password!<br/>\n"); }
else if (!$CURRENT_USER) { alert("Invalid username or password!<br/>\n"); }

#############################//

My question is how to have dynamic data in the alert rather than the aka "Please enter a username!"

I have my login user page, and at the very top I have placed a recordset that is filtered first the other login code is under it. I have the dynamic data but so far I am at a loss how to add it to these specific alerts in themselves. I have tried in the membership associated page to change the error checking to the following 

if (!@$_REQUEST['username']) { alert("{$record['testone]}<br/>\n"); } // didnt work wowa

and

if (!@$_REQUEST['username']) { alert("{$testone}<br/>\n"); } // and that didnt work

How best can I call dynamic data to show in the alert, as i say I do have my recordset above it in the login user page thus i do have the content called for the $testone 

Grateful for any input.

Kenny

By Twocans - June 19, 2017

Dave Thank you,

I am using Website Membership v1.11

i had to place it above the  $errorsAndAlerts = alert(); // on the user-login.php page

I did try that and yes where as it kinda works on my page http://www.camteach.com/user-login.php

un ionnadugg@gmail.com pw interactivetools

if (@$_REQUEST['action'] == 'login' && !@$_REQUEST['username']) { alert("TEST: Enter a username on page"); }
else if (@$_REQUEST['action'] == 'login' && !@$_REQUEST['password']) { alert("TEST: Enter a password on page"); }
else if (!$CURRENT_USER) { alert("Test: Invalid username or password! on page<br/>\n"); }

I had to go to the plugin code in itself and change it otherwise both would fire same time thus 2 error messages.

if (!@$_REQUEST['username']) { alert(""); } // plugin code page

else if (!@$_REQUEST['password']) { alert(""); } // plugin code page
else if (!$CURRENT_USER) { alert(""); } // plugin code page

Having spent many hours with it, I feel I don't want to compromise any level of protection the plugin adds thus I feel I might stand back and let it go. But it would be nice were the plugin ever upgraded to take into account multilingual websites, as now the UK is stupidly leaving the eu most of the UK will need to start plugging itself different to all member eu states, which speak a different language. I just want a change to get in there with work if you know what I mean. 

regards

K

By Dave - June 20, 2017

Hi Kenny, 

...it would be nice were the plugin ever upgraded to take into account multilingual websites...

Sure, I didn't realize that was the issue you were trying to address.  I've released a beta here with the language strings available for translation in /plugins/websiteMembership/languages/.

You can download it here: https://www.interactivetools.com/add-ons/my_purchases.php

Can you try the beta and let me know if that works for you? It'll use the language file that matches the language you've set in the CMS Settings.  If it does everything you need I'll make it an official release.

Dave Edis - Senior Developer
interactivetools.com

By Twocans - June 20, 2017

Dave

You and the team are stars, I will have a play. I sent you an email.

cheers

Kenny

By Twocans - June 21, 2017

Dave Hello,

Thank you
I had a play with it this morning all worked fine. 

I have a recordset on my user-login page, it is filtered first on the page. 

In the return, we have this

  'Please enter a username!' => 'Please enter a username!',

How can I add dynamic value to this

I have tried

  'Please enter a username!' => '{$record['test_table_one_name']}',

and

  'Please enter a username!' => '{$test_table_oneRecord['test_table_one_name']}',

But neither worked. 

thank you

kenny

By Dave - June 22, 2017

Hi Kenny, 

There's no built in way to do that, so you're back trying to replace or override the existing alerts.  You'd need to either add the error checking code yourself and/or replace the errors that are provided.  All of which takes some custom PHP code.

If you want to keep working on that here's a sample script that shows you how to replace a placeholder in alert().  Note that we're accessing an internal variable here so it might stop working at some point in future if we change things.  However we have no plans to change it anytime soon.

// load viewer library
$libraryPath = 'cmsb/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/sb/cmsb3/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// Set some alerts
alert("Test\n");
alert("Hello #username#\n");
alert("Bye\n");

// show what they're set to.
print "<p>Alert is set to: ";
print alert();

// replace value in alerts
$username = "Joe User";
$APP['alerts'] = str_replace("#username#", $username, $APP['alerts']);

// Show what they're set to now
print "<p>Alert is set to: ";
print alert();

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

By Twocans - June 23, 2017

Thank You Dave,
I am very grateful

cheers

Kenny

By Twocans - July 5, 2017

Wow,
Dave Hi,
I have given it a good go over time but nope

ref

if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can access this page."); }

// replace value in alerts
$username = "Joe User"; // i expect to see error Joe User but it doesn't work wowa
$APP['alerts'] = str_replace("#username#", $username, $APP['alerts']);

------------------------------------------------

I have checked the error in itself and tried to play with it but to no avail. 

// error checking
if (!@$_REQUEST['username']) { alert(t("Please enter a username!"). "<br/>\n"); }

http://www.camteach.com/user-login.php

if i can manage to do one error I can do all of them.

regards

Kenny

By Dave - July 5, 2017

Hi Kenny, 

Ok, I created a user-login page and tried this myself.  I believe the issue is that the value of $APP['alerts'] gets assigned to $errorsAndAlerts.  Try this code in red and then entering a username and a blank password.  You should get an error "Please enter a secret code-word!".

  // error checking
  $errorsAndAlerts = alert();
  if (@$CURRENT_USER)                                { $errorsAndAlerts .= "You are already logged in! <a href='/'>Click here to continue</a> or <a href='?action=logoff'>Logoff</a>.<br/>\n"; }
  if (!$CURRENT_USER && @$_REQUEST['loginRequired']) { $errorsAndAlerts .= "Please login to continue.<br/>\n"; }

  // save url of referring page so we can redirect user there after login
  // if (!getPrefixedCookie('lastUrl')) { setPrefixedCookie('lastUrl', @$_SERVER['HTTP_REFERER'] ); }

  // replace messages in $errorsAndAlerts - DO THIS LAST
  $errorsAndAlerts = str_replace("password", "secret code-word", $errorsAndAlerts);

?><h1>Sample User Login Form</h1>

<!-- USER LOGIN FORM -->
  <?php if (@$errorsAndAlerts): ?>
    <div style="color: #C00; font-weight: bold; font-size: 13px;">
      <?php echo $errorsAndAlerts; ?><br/>
    </div>
  <?php endif ?>

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com