Welcome, Guest
Username: Password: Remember me

TOPIC: validating the values of a column using a table

validating the values of a column using a table 10 Aug 2012 13:08 #3086

Is there way without COOK to validate the values of a field by using a table with the correct values.
p.e. I have a field CURRENCY and i want to make sure the value that is entered comes form a column CODE on my table, and that column contains 'EUR','USD',YEN',...
The administrator has disabled public write access.

Re: validating the values of a column using a table 10 Aug 2012 13:15 #3087

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Very easy. (since jQuery validator)


TODO :
1. Add a js validator handler in helpers/html/validator.php ex : currency
2. Concat all these values to create a long regex. (can be generated dynamically by your component, better)
3. Create the languages strings associated (same file)
4. Add a class name to the field to validate : 'validate[currency]'

Note : to add a class to a JDom input :
..array(
...
"domClass" => 'validate[currency]'   // for the previous exemple
)..

Hope it helps.


EDIT : After reflexion, I think here it is better to do not use a SQL call to concat the currencies. It is a call each time the validator is instancied in the component, even if the form do not need this to validate.

So I would suggest a kind of cache file regenerated when the currencies are edited. Or eventually regenerated only if the validation is asked. (Coding only in this new component).

So the previous code is valid, but the regex is read from a file. Much better.
Coding is now a piece of cake
Last Edit: 10 Aug 2012 13:26 by admin.
The administrator has disabled public write access.

Re: validating the values of a column using a table 10 Aug 2012 13:27 #3088

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Up, to notify the edition of the topic.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: validating the values of a column using a table 10 Aug 2012 13:28 #3089

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
And I add that this validation is JS only.

With the coming of JForms (soon), you will be able to create a 'rule', which is a bridge between JS and PHP.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.090 seconds

Get Started