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

g089h515r806’s picture

It 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.

Liam Morland’s picture

I agree. I tagged this D8 because it might be best to merge our modules starting in D8.

Liam Morland’s picture

Issue summary: View changes
rodrigoaguilera’s picture

This change might be relevant https://www.drupal.org/node/2438011

g089h515r806’s picture

validation for configable field Drupal8
https://www.drupal.org/node/2247085

giorgio79’s picture

How 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

Liam Morland’s picture

I think we should embrace whatever approach D8 is taking.

Liam Morland’s picture

@g089h515r806 Are you interested in pursuing this idea?

g089h515r806’s picture

In 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.

Liam Morland’s picture

Do 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?

g089h515r806’s picture

I 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.

Sam152’s picture

I'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:

  • They have a conditionals system wrapped around them which can impact the built in validations.
  • They can be individual items that are part of a larger composite element.
  • They have their own system of cardinality.
  • Elements can be split into multi-page wizards.

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.

Liam Morland’s picture

Those 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.

jnicola’s picture

I 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.

Liam Morland’s picture

Webform 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.

Liam Morland’s picture

Is 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.