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.
Comments
Comment #1
dwwrobert, can you comment on weburl should support internal links?
thanks,
-derek
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentedhuh? drupal has valid_url() already. is this more of a form api request?
Comment #3
robertDouglass CreditAttribution: robertDouglass commentedYeah. 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.
Comment #4
sodani CreditAttribution: sodani commentedI think that this would be a very valuable feature.
Comment #5
KarenS CreditAttribution: KarenS commentedRemoved weburl from cvs, please use link instead (http://drupal.org/project/link). Weburl is not being maintained.
Comment #6
KarenS CreditAttribution: KarenS commentedOops, 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.
Comment #7
yched CreditAttribution: yched commentedhttp://drupal.org/node/97806 by webchick has been marked duplicate.
Comment #8
mki CreditAttribution: mki commentedThis 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.
Comment #9
KarenS CreditAttribution: KarenS commentedAnother duplicate of this issue is at http://drupal.org/node/104339.
Comment #10
KarenS CreditAttribution: KarenS commentedAnother duplicate of this issue is at http://drupal.org/node/104412.
Comment #11
KarenS CreditAttribution: KarenS commentedThis 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!
Comment #12
sstrudeau CreditAttribution: sstrudeau commented"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.
Comment #13
floretan CreditAttribution: floretan commentedI 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).
Comment #14
mfbI'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...
Comment #15
moshe weitzman CreditAttribution: moshe weitzman commentedNow 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.
Comment #16
xjmHas there been any recent activity on this issue? I think integrated client- and server-side per-field validation would be an amazing feature.
Comment #17
nadavoid CreditAttribution: nadavoid commentedRe. #15 - Is there a way to browse just forms component issues in the core project? I'm not seeing a way to filter to just one component.
Comment #18
dwwRe #17: Yes.
Start at the core issue queue here:
http://drupal.org/project/issues/drupal
Click on "Advanced search", brings you here:
http://drupal.org/project/issues/search/drupal
Use the multi-select form element called "Components", scroll down and select "forms system". Press "search"
If you click on the little "permalink" # character at the bottom of the page, you'll have something you can bookmark for later:
http://drupal.org/project/issues?projects=3060&components=forms%20system...
Comment #19
nadavoid CreditAttribution: nadavoid commentedPerfect. Thanks! Advanced Search is what I was missing. That permalink will be very useful too.
Comment #20
steinmb CreditAttribution: steinmb commentedLet's move this to D8 then. Not much have changed I guess, but there is work done in #1318938: An all-embracing attempt for URL validation and Input / Output Form Filtering regarding this issue and similar ones.
Comment #21
kenorb CreditAttribution: kenorb commentedDuplicates or validation related:
4.x
#83841: regex text-field validation
#76467: Patch to allow regular expressions in allowed values field
#85254: How to get CCK to validate for length in textarea?
#104412: Validators
http://drupal.org/node/134289
5.x:
#203992: php validation code support
6.x
#97806: Adding some sort of validation API to CCK
#212665: Custom validating hook for CCK
#118417: Regexp field type
#84791: Regular Expression matching on text field allowed values
#251549: General validation code option for field types like text field
#97983: Live JavaScript validation of fields
#104339: Future of CCK ??
7.x
#1318938: An all-embracing attempt for URL validation and Input / Output Form Filtering
#912698: Validation on CCK Core
Alternative Modules:
5.x: http://drupal.org/project/cck_validation
6.x: http://drupal.org/project/validation_api
7.x: http://drupal.org/project/field_validation
Comment #22
nod_An issue back from the dead :)
new HTML5 input types have client side validation in supported browsers, a required attribute and there is also a
pattern
attribute holding a regex. Polyfill available for IE8+ and other browsers.Comment #23
kenorb CreditAttribution: kenorb commentedI'm not sure if it's outside of scope of this issue (server validation), but my proposal in #912698: Validation on CCK Core was to create 'Validation function' textfield, the same as there is already: 'Allowed values function' for selectlist widget.
Or create pre-populated dropdown with most popular Drupal validation functions from the core (like valid_email_address) and modules can add their own validations by defining them in dedicated hook.
Or this issue is focused on HTML5 validation only?
Comment #24
nod_Well if there is a revamp of the validation API/UI, HTML5 things needs to be included as well as server-side work.
Comment #25
kenorb CreditAttribution: kenorb commentedTested field_validation module, and actually it does a good job in Drupal 7.
Comment #26
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedtl;dr: We have some new HTML5 elements, that obviously can be used as they are, with all the server side validation, but you can also use their FAPI validation callbacks independently: form_validate_url(), form_validate_color(), form_validate_number(), form_validate_email().
Comment #27
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedWe also have support for regexes as of #1174766: Support the #pattern FAPI property for native HTML5 pattern attribute. What other common things would we like to have?
Comment #28
nod_We should look into the setCustomValidity thing of HTML5 forms #1797438: HTML5 validation is preventing form submit and not fully accessible
Comment #29
mgiffordAdding a related issue #742344: Allow forms to set custom validation error messages on required fields
and bumping this issue up to critical as per @nod_'s comment in the other issue queue.
Comment #30
attiks CreditAttribution: attiks commentedI created #1845546: Implement validation for the TypedData API to try to solve this on all levels, since there are only 10 days left, we need to figure out what needs to be done before feature freeze and what can be done later.
Comment #31
effulgentsia CreditAttribution: effulgentsia commentedThis issue in #30 landed, and we have #1696648: [META] Untie content entity validation from form validation open as a critical task. Given that, is there something distinctly useful being tracked in this issue, or should we close it?
Comment #32
moshe weitzman CreditAttribution: moshe weitzman commentedNo reply so closing this. Reopen if we really do need this.