Validation API/UI
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | forms system |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
It would be nice if we could have a library of validation functions which could be added to any field's validation stack. For example, for weburl I wrote a function to validate whether a text field contains a valid URL. If there were a way to map the existing and available validations to a field's validation, it wouldn't have been necessary to write a new module for weburl; I would have been able to just add the validation.
Of course, the roadblock to doing this really correctly is the missing rules toolkit. Adding validation rules would ideally include AND/OR logic, and this gets tricky. I'd settle for only AND logic at the beginning.

#1
robert, can you comment on weburl should support internal links?
thanks,
-derek
#2
huh? drupal has valid_url() already. is this more of a form api request?
#3
Yeah. I guess. FAPI field types would be kewl.
I have to re-look at the drupal function but I think the validation I did was a bit more... something. Anyway, its clear that the field type needs work, and all suggestions are welcome.
#4
I think that this would be a very valuable feature.
#5
Removed weburl from cvs, please use link instead (http://drupal.org/project/link). Weburl is not being maintained.
#6
Oops, I read this too quickly and closed it because of the reference to weburl. The idea of a validation library still makes sense, so I'm re-opening.
#7
http://drupal.org/node/97806 by webchick has been marked duplicate.
#8
This isn't new problem so I think we should get acquainted with the ready solutions. I value the way, especially simplicity, that validation is implement in Zend Framework. Look at Zend_Filter_Input and Zend_Filter classes. If we can't adapt the code, just take the concept.
#9
Another duplicate of this issue is at http://drupal.org/node/104339.
#10
Another duplicate of this issue is at http://drupal.org/node/104412.
#11
This is obviously an issue lots of people are interested in, since it keeps getting added (note all the duplicates), and JonBob has said in the past that he is interested in having a flexible validation system that the fields can hook into, so I don't think there is any question whether or not something like this would be accepted. The problem is that no one has proposed even the beginnings of code to actually do it.
This is a complex subject that probably needs to be hashed out in a way that isn't easily done on the issue queue. I suggest that some of the people who are interested in it go over to the CCK group on Drupal Groups and start a discussion about how best to go about this. When it matures to the point that someone can actually create some code to do it, bring it back here and propose it as a patch that we can work on.
Thanks!
#12
"would be nice" - if the validation rules could be written once to produce both javascript (yay jQuery) AND server-side validation, so if users have js turned on the form can alert them before they get all the way to "submit" that the form isn't valid... that'd be hot.
#13
I think it's important to make a difference between single-field validation and form validation involving some relationship between fields.
For validating individual fields, one possibility would be to add the "custom php code returns true" option to the "allowed values" setting of the text field widget (something similar to what is done for custom visibility for blocks).
I'm not sure how this should be implemented (maybe with the same method mentioned above if it is possible to access other fields like computed_field.module does, but it would be nice to have a more user-friendly interface), but validating the relationship between different fields would allow much more robust forms.
We could then check that a "start date" comes before an "end date" field, or make sure that when using fieldgroup.module that every single row has correct values for every column (right now we can only guarantee that every column isn't empty, so we're dealing with a list of lists instead of an actual 2-dimensional table).
#14
I've found the jQuery "validate" plugin to be quite useful and easy. it's available via a little helper module for miscellaneous jQuery plugins: http://drupal.org/project/jquery_plugin
Of course, more work would be needed for write-once validation rules on the server and client sides...
#15
Now that widgets are pure fapi elements, i think this request applies to core, not to cck. IOW, "make a validation directory for any form element." Once such a directory exists, it isn't too hard to imagne a UI for managing validators.
Moving to core project, forms component.
#16
Has there been any recent activity on this issue? I think integrated client- and server-side per-field validation would be an amazing feature.