It would be completely awesome having the possibility to set a validation function on a per form element level! A separate admin interface (admin/settings/webform/validators) would be enable ste admins to create validation roles. Validation roles are created using textareas in which php can be put. $form and $form_state will be available just like in webform create / edit. A few default validators will be shipped with webforms. Each created validator can be attached to a component using a selectbox.

I think several patches are required for this.

Comments

quicksketch’s picture

skilip and I briefly discussed this on IRC, but I think we might have misunderstood each other slightly.

What I'd like in Webform is a system for providing validators on an element level. Webform would ship with a set of validators including:

- Numeric value (integer or decimal)
- Minimum and max length
- Match value of another component
- "Unique" value
- Required (of course)

I'm not keen on adding *more* custom PHP validators. In fact I wish I could get rid of the existing validation and processing fields we have already. Simply because putting PHP code into text areas and storing the database is extremely difficult to manage, debug, program, and be secure. I imagine thousands of sites are out there letting users insert PHP into Webforms, unaware that they're a single line of code away from loosing all their data by a single "db_query('DROP DATABASE')".

So in summary, Webform won't be adding any sort of "type in PHP code and save as a validator" functionality. However, I'm very keen on providing a public hook (say hook_webform_validators) that provides a list of validators that can be applied to certain components. Then if really desired, "Webform custom validators" could be a separate module that provides a UI for setting up validators through an interface.

skilip’s picture

It was not my intention to add textareas in component-edit forms for adding php validation. My intention is to create the validation snippets from an separate admin page. This can be a restricted area

quicksketch’s picture

Restricted or not, that definitely fits into "type in PHP code and save as a validator" functionality. I'm doing everything I can to *remove* custom PHP textareas, I'm not going to add any new ones to the core Webform project.

skilip’s picture

And how about just regexps?

quicksketch’s picture

Regex! That's one of the other validators I'd definitely like to include in Webform. In such a situation, we'd definitely need to make the error message customizable, since you don't want to show the user the regex and say "You must enter a pattern matching /[\d]{3}\-[\d]{3}\-[\d]{4}/". You'd want to say, "You must enter a phone number in the format 123-456-7890."

skilip’s picture

I'm beginning to wonder whether or not this could either be useful for CCK fields. If so, a contrib module is the place to start after all.

quicksketch’s picture

Title: Webform Element validation » Webform element validation system
Version: 6.x-2.7 »

Moving to 3.x.

weizrd’s picture

is there any way to negate validation? I'm trying to remove option of filling in emails starting with "www.", but i couldn't find any solution using regex (although i think i'm looking in the right direction).
Any idea?

thanks.

gregarios’s picture

This module and the Webform Validation module need to combine forces here.

quicksketch’s picture

Version: » 6.x-3.1
Status: Active » Closed (fixed)

I think for the time being, I'm perfectly fine with just recommending Webform Validation entirely. The module works great and the maintainer is sharp, so I don't see much reason to merge the two.