kitesmite
Posts: 12
|
| Posted: 06/24/2008, 10:08 AM |
|
How to compare 3 field values against database with offcourse adderror function.
So if a combination of the 3 fields is allready in the database do not submit it and add an error.
_________________
Official user from 2002 as member Travel-Net.
Official user from 2007 member as Kitesmite
Using PHP, MySQL, Apache
Origin: NL, Timezone GMT+1 (Forumtime +9) |
 |
 |
wkempees
Posts: 1679
|
| Posted: 06/24/2008, 11:43 AM |
|
OnValidate for the Component, The RecordForm that is.
How? click any textbox, Properties, Events, OnValidate add action 'RequiredValue'.
Tha will give you working code for the error(), and an idea of how to do a validate.
Then remove that action.
Click the Record properties Event OnValidate and add code.
Take the copied error() code.
Then do your lookup(s).......
Or do a Dlookup() as Action......
What is your condition 3 fields from one two or three tables?
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
maxhugen
Posts: 272
|
| Posted: 06/24/2008, 8:26 PM |
|
Here's an abbreviated example from some code I use to check a new user who is registering:
As Walter said, its in the form's OnValidate event.
Perhaps you can modify this to suit your requirements?
function person_OnValidate(& $sender)
{ ....
$db = new clsDBEIP_MySQL();
$dupe_email = CCDLookUp("COUNT(*)","person","Email=".$db->ToSQL($Component->Email->Value,ccsText),$db);
$dupe_login = CCDLookUp("COUNT(*)","person","UserLogin=".$db->ToSQL($Component->UserLogin->Value,ccsText),$db);
$db->close();
// Check that the email is unique
if ($dupe_email) {
$Component->Errors->addError("The Email address you entered has already been used.");
// Check that the email is unique
} elseif ($dupe_login) {
$Component->Errors->addError("The Login Name you entered has already been used.");
// Check that the new password isn't the same as the login
} elseif ($Component->UserPassword->Value == $Component->UserLogin->Value) {
$Component->Errors->addError("The Password can't be the same as your Login Name");
// Check that the confirmation is the same as the new password
} elseif ($Component->PasswordConfirm->Value != $Component->UserPassword->Value) {
$Component->Errors->addError("The Password and the Password Confirmation don't match");
// Check that the password length is adequate
} elseif (strlen($Component->UserPassword->Value) < 5) {
$Component->Errors->addError("Password length must be more than 4 characters (letters and/or numbers)");
}
}
HTH
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
kitesmite
Posts: 12
|
| Posted: 06/24/2008, 11:21 PM |
|
Hi to all,
My condition will be at least 3 fields from one table, lets say weeknumber, project_id and user_id.
I think a fourth field is necessary to make it unique and date proof, so as an extra bonus the year field must also be added.
Thanks for the Code. After ten hours of programming i didn't see it anymore, but now is a fresh day8 -)
_________________
Official user from 2002 as member Travel-Net.
Official user from 2007 member as Kitesmite
Using PHP, MySQL, Apache
Origin: NL, Timezone GMT+1 (Forumtime +9) |
 |
 |
damian
Posts: 838
|
| Posted: 12/21/2008, 3:58 AM |
|
thanks Walter and Max...
worked perfectly - but why did you build a function and what did you replace with "..."?
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
damian
Posts: 838
|
| Posted: 12/21/2008, 4:41 AM |
|
i made a couple of changes that may or may not suite someone elses use -
i wanted to check that the Bar Codes being enterred were on the list (in my database).
also using the elseif statement meant that one error at a time was displayed so i changed it to another if statement.
i also added another label beside each of my text fields so that i could bring extra attention to the incorrect values...
// Form Validation
$db = new clsDBcomp();
$code1 = CCDLookUp("COUNT(*)","valid","valid_code=".$db->ToSQL($Component->entrant_code1->Value,ccsText),$db);
$code2 = CCDLookUp("COUNT(*)","valid","valid_code=".$db->ToSQL($Component->entrant_code2->Value,ccsText),$db);
$db->close();
// Check that the bar_code_1 is valid
if (!$code1) {
$Component->Errors->addError("An Incorrect Product Bar Code 1 has been enterred.");
$Component->errorCode1->SetValue("<br><img src='images/sad.jpg'> An Incorrect Product Bar Code 1 has been enterred.");
// Check that the bar_code_2 is valid
} if (!$code2) {
$Component->Errors->addError("An Incorrect Product Bar Code 2 has been enterred.");
$Component->errorCode2->SetValue("<br><img src='images/sad.jpg'> An Incorrect Product Bar Code 2 has been enterred.");
}
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
|