Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In my usecase I had to check, if the sent value is equal to the given default-value for the specific component. I solved that by writing a new validation rule "not_default_value" in webform_validation.validators.inc:
Added to function webform_validation_webform_validation_validators()
'not_default_value' => array(
'name' => "Not default value",
'component_types' => array(
'select',
'textfield',
'textarea',
'email',
'hidden',
),
'custom_error' => TRUE,
'description' => t('Verifies that the specified component is not the default value for that component.'),
),
Added to webform_validation_webform_validation_validate()
case "not_default_value":
foreach ($items as $key => $val) {
if (is_array($val)) {
$val = _webform_validation_flatten_array($val);
}
if($val == $components[$key]['value']) {
$errors[$key] = _webform_validation_i18n_error_message($rule);
}
}
return $errors;
break;
It would be great, if there could be an output for an individual error-class for the specific compontent like "error-defaultvalue", but I don't know how to build that (jet).
Comment | File | Size | Author |
---|---|---|---|
#2 | webform_validation_equal_default-1290216-2.patch | 4.17 KB | Anonymous (not verified) |
#1 | webform_validation_equal_default-1290216.patch | 1.49 KB | Anonymous (not verified) |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedSorry - forgot the Patch-File...
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedRebuilt patch for current module-version (7.x-1.1).
Comment #3
Liam MorlandComment #4
svendecabooterThanks for your contribution freudenreichmedia.
The validation rule seems to work fine, so I committed it to the 6.x and 7.x branch.
Sorry for the long wait.
Comment #5.0
(not verified) CreditAttribution: commentedError-Correction in Text.