CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 returning login details via email

Print topic Send  topic

Author Message
PeterJ


Posts: 90
Posted: 02/05/2005, 8:21 AM

I have got into a mess and I was hoping someone could assist with a bit of clear thinking!

I have devised a form that returns login details via email. I thought it worked fine until I realised it was returning mail to all who attmepted to retrieve login in details. In the instance where an individual was not a member a blank email is generated obviously with no information. I want to prevent the script from sending email to those who are not in the database.

I've included the script below. Can anyone help me solve this riddle please?

Thank you

//BindEvents Method @1-BBFAF274
function BindEvents()
{
global $request;
$request->emailadd->CCSEvents["OnValidate"] = "request_emailadd_OnValidate";
$request->CCSEvents["OnValidate"] = "request_OnValidate";
}
//End BindEvents Method

//request_emailadd_OnValidate @4-3BF11F8F
function request_emailadd_OnValidate()
{
$request_emailadd_OnValidate = true;
//End request_emailadd_OnValidate

//Custom Code @9-002688B1
// -------------------------
global $request;
// Write your own code here.
// -------------------------

$db = new clsDBconnection();// <- Database Connection

$to = $request->emailadd->GetText();
$User_Name=CCDLookUp("emailadd", "members","emailadd= ".CCToSql($to,ccsText),$db);
$userpass=CCDLookUp("membernumb", "members", "membernumb= ".CCToSql($to,ccsText),$db);

$subject = "Your Login Details";
$message = "You have requested your login details."."\n"."\n"."Your Membership Number has been

requested at this email address: " .$User_Name ."\n"."\n"."Your Membership Number is: " .$userpass

. "\n" ."\n";
$from = "mail@mydomain.com";
$additional_headers = "From: $from\nReply-To: $from\nContent-Type: text/plain";
mail ($to, $subject, $message, $additional_headers);
//End Send Email
//End Custom Code

//Close request_emailadd_OnValidate @4-7AA2F1E4
return $request_emailadd_OnValidate;
}
//End Close request_emailadd_OnValidate


//request_OnValidate @3-BFAC7F10
function request_OnValidate()
{
$request_OnValidate = true;
//End request_OnValidate

//Custom Code @8-002688B1
// -------------------------
global $request;
// Write your own code here.
// -------------------------
$db = new clsDBconnection();
$db->query("SELECT * FROM members WHERE emailadd=\"".$request->emailadd->Value."\"");
$db->next_record();

if($db->f("emailadd") == ""){
$request->Errors->AddError("\n"."The email address is not registered");
// the email address was not found in the data base --> return Error to the user
}else{
$request->Errors->AddError("\n"."Your email has been dispatched");
}
//End Custom Code

//Close request_OnValidate @3-C7DFC077
return $request_OnValidate;
}
//End Close request_OnValidate
View profile  Send private message
peterr


Posts: 5971
Posted: 02/05/2005, 12:46 PM

Hi,

Does the 2nd part of your code work correctly - the one that displays the messages "The email address is not registered" and "Your email has been dispatched"?
If so, then maybe it would be better to move your 1st part of the code into that 2nd part (in form's OnValidate event). You would send email after the "else" statement where you display the message "Your email has been dispatched". This also would be more consistent since you would guarantee that the email is sent only when you display the message that says so.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
PeterJ


Posts: 90
Posted: 02/05/2005, 11:40 PM

Thanks peterr

I can see where I have gone wrong. I placed a validation on the form and one on the text (entry) box.

I have now placed the latter script above the section that dispatched the email and removed the custom code event from the form. However I now need to stop the script working if the email is invalid. I have placed "die();" temporarily at the end of the "The email address is not registered" section to test and all is well.

Can you advise me how to pause the script here rather than use the "die();" declaration which is using a sledgehammer to crack a nut so to speak!

Thank you for the clear thinking!

View profile  Send private message
peterr


Posts: 5971
Posted: 02/06/2005, 12:13 AM

I'm not sure which part of the script you'd like to stop.
Once you use the "AddError" method then CCS should display this message to the user and stop further execution of the page (like Insert/Update).
Or do you want to stop something within your custom code? If so, could you post your latest code here again.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
PeterJ


Posts: 90
Posted: 02/06/2005, 12:20 AM

I wanted the code to stop if the email address was invalid. Without "something" to stop the code executing at this point a blank email was sent to the email address entered in the textbox.

I have found a solution which works. I've removed

$request->Errors->AddError("\n"."The email address is not registered");

and replaced it with:

header("Location: validate.php");
die();

This may not too elegant but it does work.

If you would like me to post the code let me know. I don't want to flood the forum unnecessarily.
View profile  Send private message
peterr


Posts: 5971
Posted: 02/06/2005, 12:31 AM

I think that if you place that code within the "if" part of the statement then the other part within "else" wouldn't be executed, and vice-versa.
So rather then stopping the code I would just place all the code within the "if" and "else" sections.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
PeterJ


Posts: 90
Posted: 02/06/2005, 12:58 AM

I'll work on that

Thank you for your help

Regards

PeterJ
View profile  Send private message
Damian Hupfeld
Posted: 02/06/2005, 4:01 AM

I would like to see your code.

Damian

"PeterJ" <PeterJ@forum.codecharge> wrote in message
news:54205d35ee60c2@news.codecharge.com...
>I wanted the code to stop if the email address was invalid. Without
>"something"
> to stop the code executing at this point a blank email was sent to the
> email
> address entered in the textbox.
>
> I have found a solution which works. I've removed
>
> $request->Errors->AddError("\n"."The email address is not registered");
>
> and replaced it with:
>
> header("Location: validate.php");
> die();
>
> This may not too elegant but it does work.
>
> If you would like me to post the code let me know. I don't want to flood
> the
> forum unnecessarily.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

PeterJ


Posts: 90
Posted: 02/06/2005, 4:41 AM

Here you are Damian

<?php
//BindEvents Method @1-B27506D0
function BindEvents()
{
global $request;
$request->emailadd->CCSEvents["OnValidate"] = "request_emailadd_OnValidate";
}
//End BindEvents Method

//request_emailadd_OnValidate @4-3BF11F8F
function request_emailadd_OnValidate()
{
$request_emailadd_OnValidate = true;
//End request_emailadd_OnValidate

//Custom Code @9-002688B1
// -------------------------
global $request;
// Write your own code here.
// -------------------------

$db = new clsDBconnection();
$db->query("SELECT * FROM members WHERE emailadd=\"".$request->emailadd->Value."\"");
$db->next_record();

// members is the name of the table that holds the email address
if($db->f("emailadd") == ""){

header("Location: validate.php");
die();
// email was not found in the data base --> return Error to the user
}else{
$request->Errors->AddError("\n"."Your email has been dispatched");
}
//End Custom Code

$db = new clsDBconnection();

$to = $request->emailadd->GetText();
$User_Name=CCDLookUp("emailadd", "members","emailadd= ".CCToSql($to,ccsText),$db);
$userpass=CCDLookUp("membernumb", "members", "emailadd= ".CCToSql($to,ccsText),$db);

$subject = "Your Login Details";
$message = "You have requested your login details."."\n"."\n"."Your Membership Number has been requested at this email address: " .$User_Name ."\n"."\n"."Your Membership Number is: " .$userpass . "\n" ."\n";
$from = "mail@yourdomain.com";
$additional_headers = "From: $from\nReply-To: $from\nContent-Type: text/plain";
mail ($to, $subject, $message, $additional_headers);
//End Send Email
//End Custom Code

//Close request_emailadd_OnValidate @4-7AA2F1E4
return $request_emailadd_OnValidate;
}
//End Close request_emailadd_OnValidate



View profile  Send private message
Nicole

Posts: 586
Posted: 02/07/2005, 1:16 AM

PeterJ,
Your code send email outside if($db->f("emailadd") == "") statement. You’d rather try the code like
  
if($db->f("emailadd") == ""){  
  
header("Location: validate.php");  
die();  
// email was not found in the data base --> return Error to the user  
}else{  
$to = $request->emailadd->GetText();  
$User_Name=CCDLookUp("emailadd", "members","emailadd= ".CCToSql($to,ccsText),$db);  
$userpass=CCDLookUp("membernumb", "members", "emailadd= ".CCToSql($to,ccsText),$db);  
  
$subject = "Your Login Details";  
$message = "You have requested your login details."."\n"."\n"."Your Membership Number has been requested at this email address: " .$User_Name ."\n"."\n"."Your Membership Number is: " .$userpass . "\n" ."\n";  
$from = "mail@yourdomain.com";  
$additional_headers = "From: $from\nReply-To: $from\nContent-Type: text/plain";  
mail ($to, $subject, $message, $additional_headers);  
}  
There’s no need to open new connection before send mail code.
If you want to display a confirmation message that email has been sent you can use special session variable that stores a confirmation text, e.g.
  
...  
mail ($to, $subject, $message, $additional_headers);  
CCSetSession("confirm_mess",  "Your email has been dispatched");  
}  
On a return page of this form add Label to display this message. In Before Show event of a Label check session variable value, assign it to Label and empty session.

_________________
Regards,
Nicole
View profile  Send private message
PeterJ


Posts: 90
Posted: 02/07/2005, 9:50 AM

Thank you Nicole for tidying that for me and others.

Looks like I owe you a beer or 6:-)

Regards

PeterJ
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.