Testing for existing user account

18 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 1, 2011   (RSS)

By Jason - May 30, 2011

Hi Jerry,

There's isn't a function defined in CMS Builder called alert2(), so that's where that error is coming from.

To be sure I understand what you're trying to do, when a form is submitted, if there are errors, you want to display the form and the errors. If the form is submitted and there are no errors, you want to display a message, but not the form. Is that right?

If so, I would suggest a different approach. You can create a variable called $success and set it equal to false. You only set $success to true if the form was submitted successfully with no errors:

Example:

<?php

$success = false;
$errorsAndAlerts = "";

if (@$_REQUEST['submit']) { // form has been submitted

// error checking

...

if (!$errorsAndAlerts) { // no errors found

// code executed when form is submitted successfully

$errorsAndAlerts = "Congratulations! Your form was submitted successfully!";
$success = true;
}

}
?>


Then you can output $errorsAndAlerts whenever it has a value (either an error message or a success message) and decide whether or not to display the form independently like this:

<?php if (@$errorsAndAlerts): ?>
<div ><br/>

<?php echo $errorsAndAlerts; ?><br/>
</div>

<?php endif: ?>

<?php if (!$success): ?>

The Form Code and Instructions...

<?php endif ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Testing for existing user account

By gkornbluth - May 30, 2011 - edited: May 30, 2011

Thanks Jason,

Actually what I'm trying to do is display 2 separate (groups of) error messages and either show or hide the form and instructions depending on which message is displayed.

EXISTS NOW
The conditions which exist now, as alert():

A) Display a success message if the email address is found and a failure message if the email address is not found.

B) Hide the instructions and the form since their purpose has been accomplished, thus focusing the applicant on the next step in the signup process.

TO ADD
What I was trying to do with alert2() was to add a separate error message that shows only if the form is blank when submitted.

This condition would not hide the form or the instructions, allowing the applicant to try again.

Hope that makes more sense,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Jason - May 30, 2011

Hi Jerry,

How about this:

You can still use $errorsAndAlerts to display all messages, but then set another variable to decide if you should display the form or not. You would default this variable to true so that you show the form when the page first loads.

So the top of your page would look like this:

<?php

$errorsAndAlerts = "";
$showForm = true;

if (@$_REQUEST['submit']) {

if (!@$_REQUEST['pastInformation']) {
$errorsAndAlerts = "Please enter an email address<br/><br/>\n";

}

if (!$errorsAndAlerts) {
$showForm = false;

// check if the email address exists
}
}
?>


And the display portion of your page would look like this:

<?php if (@$errorsAndAlerts): ?>
<div ><br/>

<?php echo $errorsAndAlerts; ?><br/>
</div>

<?php endif ?>

<?php if ($showForm): ?>

The Form Code and Instructions...

<?php endif ?>


Does this look more like what you're looking for?
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Testing for existing user account

By gkornbluth - May 30, 2011

Thanks Jason,

I'll plug it in and give it a try.

You're the best

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [Jason] Testing for existing user account

By gkornbluth - June 1, 2011

Hi Jason,

My question is, is what I've done below OK, or have I opened up either security or other issues?

I wanted to allow a member who received a no record available error after submitting their email address, to be able to return to the previous page and try again with another address.

Since the error code is in the Membership Plugin, and will be called from more than one page, I added the code in red:

Thanks,

Jerry Kornbluth

// Existing Account Request
function _websiteLogin_pastInformation() {
global $SETTINGS, $TABLE_PREFIX;

$exists=0;
if(@$_REQUEST['pastInformation']){
$where = "email ='".mysql_escape(@$_REQUEST['pastInformation'])."'";
$exists=mysql_select_count_from('accounts',$where);
}
$ref=@$HTTP_REFERER;
if ($exists) {
alert("<span class='heading-text-yellow'>Congratulations!!!<br />Your Account Information Exists</span><br /><span class='body-text-yellow'>You don't
need to create a new account, just use the link below to pay your current year's dues.<br /></span>\n");
}
if (!$exists) {
alert("<span class='heading-text-yellow'>Sorry!!!<br />Your Account Information No Longer Exists</span><br /><span class='body-text-yellow'>You'll have to fill out a new membership application after you you've paid your current year's dues.<br />To search for your information using another email address
<a href='$ref'><span class='heading-text-yellow'>CLICK HERE</span></a>
<br /></span>\n");

}
}

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Jason - June 1, 2011

Hi Jerry,

Since all the function is really doing is checking to see if a value exists in the database, I don't see any security issues. The only issue with putting it inside the membership plugin is that if you ever need to upgrade the plugin, your changes will be overwritten.

A good approach to take would be to create a plugin that uses no hooks where you can put in custom functions. Since these functions are inside a plugin, they're available on any page that connects to CMS Builder.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Testing for existing user account

By gkornbluth - June 1, 2011

Thanks

I feel more comfortable now

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php