CodeCharge Studio
search Register Login  

Visual Web Reporting

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 Validate input value with a database field [SOLVED]

Print topic Send  topic

Author Message
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
View profile  Send private message
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
View profile  Send private message
jeffware

Posts: 16
Posted: 12/08/2010, 8:40 AM

Is there no way to do this within the CCS framework? with AJAX maybe?
View profile  Send private message
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
View profile  Send private message
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.
View profile  Send private message
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.
View profile  Send private message
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!
View profile  Send private message
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.");
}
View profile  Send private message
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.
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.

MS Access to Web

Convert MS Access to Web.
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.