Hi,

I was trying to add some additional validation to a webform date field using the #element_validate attribute, but it appears that when the field is going through the webform_expand_date function (in components/date.inc) called by #process the validation is set to
$element['#element_validate'] = array('webform_validate_date');

I understand that you wanted to replace some Drupal validation with webform-specific validation, but this is not really nice.. Some observations:
1. When loading the form, the date element actually has "webform_validate_date" set as the default value for the #element_validate property, so maybe that call in the processing function is outdated?
2. If you insist that it's necessary, could you please remove whatever validation you don't want explicitly from the array and add the webform validation using:
$element['#element_validate'][] = 'webform_validate_date';

This would keep the field in step with the rest of the form API and would be very helpful and appreciated!

Let me know if you need further details.

Thanks in advance,

Martin

Comments

quicksketch’s picture

The overwriting of Drupal core's validation is intentional, since it doesn't take into account things like using a textfield for the year instead of a select list. Making a change like this will not accomplish the removal of core's validation:

$element['#element_validate'][] = 'webform_validate_date';

However I think you may be right that the location of our #element_validate assignment might be misplaced. If we moved it from the webform_expand_date() function to _webform_render_date(), I think it would continue to operate properly and you'd then be able to add your own validation through hook_form_alter().

arski’s picture

Hi,

Yea, moving it there would be an option.

Just to reiterate, when I load the webform the date field already has _only_ that webform validation function set, so maybe something has changed in recent times and that full overwrite is not necessary anymore?

Another option might be to unset the Drupal validation function explicitly just in case it's still there:

unset($element['#element_validate']['drupal_validation_function_name']);

I would be happy either way you do it so I'm looking eagerly forward to having this fixed.

Thanks,
Martin

quicksketch’s picture

Status: Active » Fixed
StatusFileSize
new859 bytes
new627 bytes

Weird, well I have no idea why we have been adding the same #element_validate in two places. As far as I can tell, the second call is completely unnecessary. I've just removed the second call in the 2.x branch, and I've moved the assignment in the 3.x branch to be the same. Thanks for the report, committed these patches to all branches.

arski’s picture

Thanks a lot!

Any (approximate) idea when you'll be running a next stable release of 2.x?

quicksketch’s picture

Whenever #604958: %profile and %server default values broken gets fixed probably. Doesn't seem that anyone is really interested in fixing it (self included).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.