Custom error message setting doesnt work.
All I get is below text as an error message.

oneofseveral_4
oneofseveral_5
oneofseveral_6

Comments

g089h515r806’s picture

How to reproduce your case.

I have test it on my site, it works correktly.

Could you add other validator and test the error message?
make sure this is a bug only in "oneofseveral" validator or in multiple validators.

hgurol’s picture

I guess its a conflict with the Phone Module, http://drupal.org/project/phone

When my field type is Phone Number and the widget is Text Field, the problem is there with all validators.
When my field type is Text and the widget is Text Field, it works.

Phone Module has its own validation and own error message. I believe that's where the conflict is.

How we can solve this problem?

Thanks...

g089h515r806’s picture

I have checked the code of phone module. there maybe a bug in phone module:

$errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => t($country['error'], array('%value' => $value)),
        );

the code should be(i think):

$errors[$field['field_name']][$langcode][$delta][] = array(
          'error' => t($country['error'], array('%value' => $value)),
          'message' => t('error phone number'),
        );

'message' key was missing in phone module.

hgurol’s picture

I dont think that 'message' key is the problem but anyhow, I asked the Phone module maintainer to take a look at the issue.

Thank you...

sammyd56’s picture

I'm having the same problem with Link module.

I've submitted an issue there #1347600: Incompatibility with Field Validation module, but given that there is a similar problem with the Phone module, perhaps the problem lies in the Field Validation module's code...

hgurol’s picture

I haven't heard from the Phone module maintainer about this issue #1317010: Conflict with Field validation Module.

Maybe the conflict is with all the modules which has its own validation?

g089h515r806’s picture

I test it, it is an error.
the reason maybe come from "hook_field_process", i am not sure.
The module which has "hook_field_process" may conflict with Field validation.

g089h515r806’s picture

This is a bug, i am not sure it is derived from field validation, or Drupal Core.
It does not work very well with compound field,such as link, image,addressfeld,phone.

For single field, the error message come from "message" key, this key is required for single field.
For compound field, the error message come from "error" key, "message" key is omitted.

I find a quick solution:

$errors[$rule['field_name']][$langcode][$delta][] = array(
	'message' => t($rule['error_message']),
	'error' => t($rule['error_message']),
);

make the 'error' and 'message' the same.

g089h515r806’s picture

Test with the dev version, I have fixed.
I only test the code with Unique validator.

b-prod’s picture

I think the problem comes from Field core module, in the function field_default_form_errors() (field.form.inc file). The following code is used for widgets that do not implement [widget]_field_widget_error() function:
form_error($error_element, $error['error']);

On the Drupal API for such function (http://api.drupal.org/api/drupal/modules!field!field.api.php/function/ho...), the given example uses form_error($element['value'], $error['message']);.

So there is a conflict there, that will probably take a lot of time to be fixed. So I agree that the quick fix in #8 is a good workaround for this issue.

Moreover, in the FieldValidationException class, the errors array is clearly defined as:

An array of field validation errors, keyed by field name and
delta that contains two keys:

  • 'error': A machine-readable error code string, prefixed by the field module name. A field widget may use this code to decide how to report the error.
  • 'message': A human-readable error message such as to be passed to form_error() for the appropriate form element.
b-prod’s picture

Here is a patch against Drupal core to correct this issue without hacking the code of Field Validation, which is the correct and expected one.
#1432732: Form error reporting fallback does not respect Drupal documentation (first comment)

@g089h515r806: Actually, I am not so sure that putting the error message in the 'error' key is a good idea, since it breaks with the expected behavior and documentation. It could be better to suggest a patch file awaiting this issue is fixed in Drupal core, but keep the Field Validation module code clean.

g089h515r806’s picture

$errors array of Drupal core does not support a field with several form elements.
It work for a field only have one form element.

g089h515r806’s picture

Status: Active » Needs review

test the latest dev code which fix this issue.

Anonymous’s picture

I had this issue with regex-validation of a link field.

It's fixed in the dev code. Great work, g089h515r806!

g089h515r806’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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