I'm sorry if this has already been suggested, but I couldn't really find much searching through Drupal.org and the queue(other then a module that was looking to do something related for cck textareas in drupal5)

Basically core CCK field types like "Text Field" currently offer some validation through the "Allowed Values" admin section where you can enter (or programatically create) an array of allowed values. However, what I'd like is the chance to actually enter PHP code for complete validation on the field. Like give me a handle to use for the value entered and let me return TRUE or FALSE after some php code validation.

It seems that this would make the Text Field *much* more powerful as we could "make" something like a phone number field with validation within the admin, without creating a custom CCK field module for it.

I haven't yet looked at what it will take for me to hook my own validation into CCK fields I create via a seperate module, so maybe this is rather trivial to do anyways. But either way, I don't think it would be as simple as an option when creating the field :)

Thanks for everyone's work with CCK!

Comments

xjm’s picture

There exists a validation module (looks like there's only a D5 release at present):
http://drupal.org/project/cck_validation

However, this module adds a widget to create a pseudo-field that validates the whole node. I think it would make more sense to allow a custom validation PHP snippet on a per-field basis in the CCK framework.

What would be really, really awesome would be to allow this field validation to happen in an AJAX-y fashion if the user chooses, so that the user could get feedback on whether the field was valid before submitting the form, and fall through to good old form_set_error() or some such if not AJAX-enabled.

I can't imagine we're the first two people to be interested in this, so I'm going to dig around a bit and see if I can find other relevant projects or issues.

xjm’s picture

Status: Active » Closed (duplicate)

I found a more active issue on CCK validation (so setting this one to duplicate):
http://drupal.org/node/52051

Looks like the intent there is to possibly fold this functionality into the core form handling in D7. Doesn't help me back here in D5, though. :)

In the meanwhile, I am going to check out using http://drupal.org/project/jquery_plugin in concert with the CCK Validation module. It's somewhat tedious to have to do duplicate work to get both client- and server-side validation, but I guess it's the best option at present.

xjm’s picture

Found a proposed patch for per-field validation (looks like it hasn't seen much testing):
http://drupal.org/node/203992

Related posts:
http://drupal.org/node/134289
http://drupal.org/node/220018
http://drupal.org/node/97983

Moonshine’s picture

This is the project I'm keeping an eye on...

http://drupal.org/project/validation_api

xjm’s picture

Aha! That looks promising. Thanks Moonshine.

kenorb’s picture