CCK is one of the most widely used contributed modules for Drupal. It
allows site administrators to customize their content types by adding any
number of additional fields (text, number, date, image...), without writing
a single line of code.
One missing feature is user-configurable validation steps, that currently
do require manual coding and trickery. This has lead to the proliferation
of CCK field modules that are simply a text field with some formatting
logic applied to them, such as for a UK telephone number, a US social
security number, an email address... In many cases, however, a full CCK
field module is unnecessary and all that is needed is extra validation
capability, which would eliminate a lot of needless code and provide
additional flexibility for site administrators.
The goal of this task is to add a support for user-configurable validators
for any CCK field type. It should be targetted as a patch to the HEAD (for
Drupal 6) version of CCK's content.module.
* When configuring a field, as part of the field configuration (not widget
configuration), allow the user to select a validation rule from a list.
Each validation rule must have a name/label and optionally a minimal
configuration. Use of Drupal 6's new AHAH-add-fields functionality here is
encouraged.
In order to simplify the form workflow management, the scope of this task
is limited to 1 validation rule per field for now.
* The list of available validation rules will be provided by a new hook,
exposed by the content.module. Any module may define an arbitrary number of
validators that it offers for any field type. Each validator should work by
accepting the value of the field and the configuration of the validator (if
applicable) to a callback function and returning TRUE (indicating that it
passes validation) or FALSE (indicating that it failed).
* When validating a submitted field, the content.module should call the
configured validator with the submitted content. If the validator fails,
the field should fail validation with an appropriate error message.
* At least two validators for text fields will be implemented in this task
: A user-defined regular expression (PCRE) and user-supplied PHP code that
will return TRUE or FALSE.
* Although it is not required for this task, a later task will include
pushing a regular expression check out to the user-side where it can be
validated with Javascript/jQuery as well. Do not implement that
functionality here, but keep it in mind so that it is reasonable to add it
later.
The API for validators can be largely derived from the existing API for
widgets and formatters :
- hook_validator_info() lets modules declare the validators they implement,
along with the field type(s) they can operate on.
- hook_validator_settings() lets them declare the $form to use for settings
(just like 'form' / 'save' ops for hook_widget_settings)
- hook_validator() performs the actual validation of the field values.
The task is completed when the patch has been posted to the CCK issue queue
and reviewed and marked "Ready to be committed" by one of the CCK maintainers.
Mentors :
yched, KarenS
Ressources :
- CCK HEAD for Drupal 6 : http://drupal.org/node/96064
- the sample fields provided in the 'examples' folder in CCK HEAD.
- 'CCK for developpers' handbook : http://drupal.org/node/101742
Comments
Comment #1
yched commentedThe official task associated with this issue can be found at http://code.google.com/p/google-highly-open-participation-drupal/issues/...
Comment #2
webchickThis didn't end up getting claimed during the GHOP task-claiming deadline, so is up for grabs for anyone who wants to work on it.
Comment #3
yched commentedhttp://drupal.org/node/84791 has been marked duplicate.
I has a patch for regexp validation on text fields that, even if less generic than the approach above, contains code that might be worth looking at for anyone willing to tackle this.
Comment #4
xjmTracking.
Comment #5
dixon_Bump. Has someone done something on this issue? How could I help moving this issue forward?
Comment #6
aren cambre commentedSubscribe. Would really like a regexp validator in CCK.
Comment #7
giorgio79 commentedhttp://drupal.org/project/validation_api
This could help as a base :)
Comment #8
markus_petrux commentedYep, it looks like that module covers the issue, and I think this won't get in (here) at this point in time where new features will be focussed on D7.
Curiously enough, Validation API is also related to 2008 Google Summer of Code, so I guess it is somehow related to this issue.
Comment #9
giorgio79 commentedCool! :)
I am really looking forward the maturation of this module, as I really miss out of the box server and client side validation just like PEAR Quickform :)
This module seems to have client side validation as well on the roadmap :)
Comment #10
sportel commentedThis looks promissing I think:
http://drupal.org/project/covert_fields
btw: Validation API is sort of abandoned I believe.
Mike.
Comment #11
giorgio79 commentedI am setting it back to "active" as the module http://drupal.org/project/validation_api is showing as abandoned...
Comment #12
drupalnesia commented:(
http://drupal.org/project/validation_api says:
Comment #13
drupalnesia commented@markus_petrux:
More than 1 year since your #8 comment, but Drupal 7 still on Drupal 7.0-alpha7 and Validation API is abandoned project now :(
Look at here: http://drupal.org/node/912698
Comment #14
karens commentedStill won't fix it here. If someone wants to figure out a way to do this it will have to be in a contrib module. And it will be much more challenging now to find a method that will work both in D6 where fields are in contrib and in D7 where fields are in core. CCK is not interested in adding completely new features to D6, we are focused on porting the ones that exist to D7.
Comment #15
aren cambre commentedI like this forward-thinking mentality. It encourages users to keep up to date instead of wasting developer time enhancing deprecated software.
Comment #16
kenorb commented8.x follow-up: #52051: Validation API/UI
Comment #17
kenorb commented