Domanda

I am using Drupal 7 installation and am using a webform to manage a submission of some data.

The fields are as follows:

  1. Date field which captures a date input
  2. Two textfields which capture numeric values
  3. Checkbox which captures a customer acceptance

I want to be able to allow the form submission based on whether:

  • (1) is greater than a certain date
  • The sum of values in (2) are greater than a certain value
  • Checkbox in (3) is checked

What would be the cleanest way of accomplishing this in Drupal 7?

È stato utile?

Soluzione 2

I ended up accomplishing this using hook_form_alter() and a callback function wired to $form['submit']['#validate'][].

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'myform') {
    $form['submit']['#validate'][] = 'validation_function';
  }
}

function validation_function($form, &$form_state) {
  // Validation logic here
  // If in validation failed set error message here
}

Altri suggerimenti

Use Webform Validation module. See http://drupal.org/project/webform_validation

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top