I recently became the D7 maintainer for the Webform Validation module and I just learned about the Field validation module. They are very similar: one does fields, one does Webforms, but the validation logic is the same, so perhaps we should be sharing that code.
It could be done like this: Make a new module "Form Validation" which contains the validation code. Sub-modules Form Validation Webform and Form Validation Field would connect the validation code to Webforms and fields, respectively. This is much like how Clientside Validation has a core module and separate modules to make it work with Webform, FAPI, Fields, etc.
Are you interested in discussing how this could work?
Comments
Comment #1
g089h515r806 CreditAttribution: g089h515r806 commentedIt will be great if there is a validation mdule that could solve all related issue.
In Drupal 8, there are a lot changes for Drupal validation, it seems that fago will add symfony validation to drupal core.
Validation will be changed to plugin system.It seems that attiks also work on validation framework for Drupal 8 core.
I think that our work need base on Drupal 8 core validation system.
Comment #2
Liam MorlandI agree. I tagged this D8 because it might be best to merge our modules starting in D8.
Comment #3
Liam MorlandRelated: #2220971: Drupal 9 version
Comment #4
rodrigoaguileraThis change might be relevant https://www.drupal.org/node/2438011
Comment #5
g089h515r806 CreditAttribution: g089h515r806 commentedvalidation for configable field Drupal8
https://www.drupal.org/node/2247085
Comment #6
giorgio79 CreditAttribution: giorgio79 commentedHow about merging all into https://www.drupal.org/project/rules_forms?
Related issue in Rules queue: #1780526: Support Entity Validation in D8
The Rules events would be the validation events eg "form field is not unique" "form field contains numbers" etc. and actions could be fail validation etc.
Or even better, given entity validation was decoupled from forms in D8, create a brand new module called Entity Validation as per https://www.drupal.org/node/2015613
Comment #7
Liam MorlandI think we should embrace whatever approach D8 is taking.
Comment #8
Liam Morland@g089h515r806 Are you interested in pursuing this idea?
Comment #9
g089h515r806 CreditAttribution: g089h515r806 commentedIn drupal 8, field validation will use constraints which provided by Drupal 8 core instead of validate form element directly, it is friendly for web service. Drupal 8 webform still validate form element directly now.
Comment #10
Liam MorlandDo you mean that the validation rules come from Drupal core and your module just connects those existing rules to fields?
What does one have to do to add a custom validator, such as validating postal codes?
Comment #11
g089h515r806 CreditAttribution: g089h515r806 commentedI mean use constraints way, if there is no constraint in Drupal core, we could add a custom constraint for it.
Constraints is decoupled from form validation in Drupal8.
Comment #12
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI'm not sure field_validation will work for webform or if even the constraints system will be flexible enough to work for webforms. Fields in webforms are a little more of an abstract concept, they currently don't map feature for feature with entity fields. They have a bunch of webform-specific complexities that I think could be relevant to an implementation of this module:
If I had to guess, I think there would be more complexity with trying to get webform concepts normalized against entity API concepts, that it would make more sense simply having these as two modules.
Comment #13
Liam MorlandThose are good points. It would be great if there could be a common API for validation rules: If someone writes a validator for some kind of string, it would be usable in both places.
Comment #14
jnicola CreditAttribution: jnicola at Oregon Health & Science University (OHSU) commentedI wrote the 8.x.1.x release of form_api_validation, I was unaware this alternative even existed! The 8.x.2.x version is using the plugin approach as well.
I'm a maintainer over there and we could figure out merging these two projects.
Comment #15
Liam MorlandWebform for Drupal 8 is a complete re-write, so Webform Validation for D8 would have to be completely different as well. So, it is a good opportunity to re-think how these things work. I think the most important thing is to keep it modular. In particular, if someone writes a validator for some kind of data, it should work everywhere. It should also be easy to write custom validators.
Comment #16
Liam MorlandIs there interest in pursuing this? I think the most important thing is that there is a common interface for validators so that someone can write a single validator and then use it anywhere: Webform, fields, or form API.