jeffware
Posts: 16
|
Posted: 12/08/2010, 1:27 AM |
|
I need to validate a value input in a form to make sure it is in a database before submitting the form. Is this possible? Thanks for any help....
Jeff
|
|
|
quasimidi
Posts: 151
|
Posted: 12/08/2010, 1:57 AM |
|
You can do the validation either on client side (using Javascript libs, such as JQuery) and/or server side, using PHP with regexp.
Some quick stuff to read:
For client side: http://www.webreference.com/programming/javascript/jquery/form_validation/
For server side:
http://stackoverflow.com/questions/737385/easiest-form-validation-library-for-php
Reagards,
_________________
RS |
|
|
jeffware
Posts: 16
|
Posted: 12/08/2010, 8:40 AM |
|
Is there no way to do this within the CCS framework? with AJAX maybe?
|
|
|
datadoit
|
Posted: 12/08/2010, 10:46 AM |
|
Please clarify: Are you validating that the record exists before
submitting the record form? or are you validating a particular field in
the record to see if it exists in another table field?
|
|
|
quasimidi
Posts: 151
|
Posted: 12/09/2010, 12:01 AM |
|
Quote jeffware:
Is there no way to do this within the CCS framework? with AJAX maybe?
Hi Jeffware,
The first link is an Ajax validation solution, used widely on the internet.
Within the CCS framework, there is no (as far as I know) ajax validation support.
Trust me, just get into it (JQuery) and it is very easy to learn+use it.
Regs,
_________________
RS |
|
|
jeffware
Posts: 16
|
Posted: 12/09/2010, 2:42 PM |
|
The validation senario is this. Table "A" will contain the data entered into the form. One field on the form (PromoCode) needs to be validated against table "B" that contains a list of valid PromoCodes.
|
|
|
ckroon
Posts: 869
|
Posted: 12/09/2010, 3:25 PM |
|
This can be done easily on the Forms On validate Event
global $DBConnection1; //use your connection name here if its not Connection1
$get = $Component->PromoCode->GetValue();//change to name of textbox where user enters Promo Code.
$check=CCDLookup('promocodeid','promocodes','promocode=. ' $get,$DBConnection1);
//change the above ccdlookup fields to match your promocodes table.
if ($check >=1)
{
$NewRecord1_OnValidate = true; //change NewRecord1 to name of your form
}
else
{
$NewRecord1_OnValidate = false; //change it here as well.
$Container->Errors->addError ("Promo Code Not Valid");
}
not tested though :)
_________________
Walter Kempees...you are dearly missed. |
|
|
datadoit
|
Posted: 12/09/2010, 3:31 PM |
|
For the form field's Validation Rule on the Data tab:
CCDLookUp("Field", "LookupTable", "Field=" .
CCToSQL($this->ThisField->GetText(), ccsText), $this->DataSource)
For the form field's Validation Text on the Data tab:
Oops! I didn't find that value!
In the Validation Rule property, it looks for NOT, so in this case if
it's NOT in the lookup table, then show the error.
|
|
|
jeffware
Posts: 16
|
Posted: 12/10/2010, 2:17 PM |
|
I will definitely try this out tonight! thanks for the help!
|
|
|
jeffware
Posts: 16
|
Posted: 12/11/2010, 5:43 AM |
|
The form validation work Great! Thanks for all the help and pointing me in the right direction! Here is the code that I added and got working in the form validation event:
global $DBConnection1; //use your connection name here if its not Connection1
$get = $registered->PromoCode->GetValue();//change to name of textbox where user enters Promo Code.
$check=CCDLookup("Field_Name","Table_Name","PromoCode='".$get."' AND Used='N'",$DBConnection1);
//change the above ccdlookup fields to match your promocodes table.
if (strlen($check) >=1) // CCDLookup returns value if found if not it is null
{
$NewRecord1_OnValidate = true; //change NewRecord1 to name of your form
}
else
{
$NewRecord1_OnValidate = false; //change it here as well.
$Container->Errors->addError ("The promotion code entered is either invalid or has already been used.");
}
|
|
|
datadoit
|
Posted: 12/11/2010, 9:13 AM |
|
Which method did you use: Property setting or Custom coding?
I'm on a big kick lately to see how much I can get away with without
custom coding. I'm finding there's a whole lot that can be done by just
using property settings and the built-in actions.
|
|
|
jeffware
Posts: 16
|
Posted: 12/11/2010, 11:30 AM |
|
I used the the code above in the validate form event. works great. Coupled with a trigger in the database it marks all the codes as used and adds them to the appropriate record in the registered database.
|
|
|