1

I've got a question about webform and webform validation.

I'm in D6.19 with webform 6.x-3.4 and webform validation 6.x-1.3

I'm adding a date field to capture age, and I need to validate that the age of the user is at least 13 years from current date.

Does anyone know how I can do this? Thanks Stephanie

  • What are you trying to accomplish here? If you use form validation, then the webform cannot be submitted until the field value is correct (in this case now - 13 years). If you are trying to block access to users under 13, then a different approach is required, say webform rules, or using a date field on user registration (again using rules). Please give us more details on your intent. – Triskelion Jun 11 '13 at 16:56
  • Hi, thanks for the reply - I absolutely intend to prohibit users younger than 13 from submitting the form. I'll check out Webform Rules. Thanks! – StephanieF Jun 11 '13 at 19:45
  • Then you definitely do not want field validation. That would keep presenting the form to the user until they entered a value which passed the validation. You need to let them submit it with the entered date, then slap their wrists for doing so :-) – Triskelion Jun 11 '13 at 20:05
0

You can do it using the hook_webform_submission_presave() exposed by the Webform api in a custom module.

Another alternative is to make use of this sandbox project

This module provides a way to calculate values for Webform components and/or to add custom validation code without the need for creating custom modules that implement hooks. It offers a PHP-like macro scripting language to use instead.

Differs from Webform PHP in that there is no eval() evil and macro code has no direct access to Drupal environment or functions, i.e. macro code is contextually jailed.

Differs also from Webform Calculator in that it permits logic-driven calculations and also integrates with the Webform Validation module.

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.