0

WebForm is a very nicely done module, but (at least at first glance) it seems to lack some things that I expect to need.

Specifically, I'd like a way to specify more complex field requirements than just a boolean. For instance, what if I have a form with an e-mail address field and a telephone field, and I want the user to be required to enter at least one of the two. In other words, if they enter an e-mail address, they don't need to enter a phone number; and if they enter a phone number, they don't need to enter an e-mail address.

Is this possible with WebForm?

1

Try using the WebForm Validation module.

The following validation rules are currently included:

  • Numeric values (optionally specify min and / or max value)
  • Minimum length
  • Maximum length
  • Minimum number of words
  • Maximum number of words
  • Equal values on multiple fields
  • Unique values on multiple fields
  • Specific value
  • Require at least one of two fields
  • Require at least one of several fields
  • Minimum number of selections required
  • Maximum number of selections allowed
  • Exact number of selections required
  • Plain text (disallow tags)
  • Regular expression
  • Must be empty (Anti-Spam: Hide with CSS)
  • Words blacklist
  • Must match a username
1

If your validation logic is complex it might be better to do that through a custom module.

There are three ways:

  1. Regular hook_form_alter() and adding your validation callback to the $form['#validate'] array.

  2. Implement hook_webform_validation_validators().

  3. Implement hook_webform_validation_validate().

See this article for more information about 2. and 3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.