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.
Error message for filling out a required date is currently like this:
- Day field is required.
- Month field is required.
- Year field is required.
- Field MyDate has errors. The year must be a number between 1 and 4000. The month must be a number between 1 and 12. The day must be a number between 1 and 31.
These are 4 lines for what is actually just 1 field. It get's even worse if you have multiple required date fields (4 error messages for each!).
Is it possible to alter this message & convert it to 1? For example: 'MyDate is required. Please fill in the correct date'.
Comments
Comment #1
rp7 CreditAttribution: rp7 commentedSince nobody hasn't noticed this yet/doesn't know a solution, here's a quick fix I'm currently using to get rid of these spammy error messages. It's dirty, but it works.
In a custom module, create a new validate function for your form:
Then, in your new custom validation function:
Hope some more experienced developers could come up with a cleaner way to solve this though. This solution removes the 3 required messages, but keeps the generic message: "Field MyDate has errors. The year must be a number between 1 and 4000. The day must be a number between 1 and 31."
Comment #2
j0e CreditAttribution: j0e commentedthanks for posting...i just used it in a custom module for a registration form which has content profile cck fields...and it worked to get rid of the three fields, though it suppressed some other errors like username and email address along with them, even with the (str_replace)...
also, i believe there's a typo at the end of the validate function in the above code, an extra (str_replace, which needs to be edited out for it to work...
form_set_error(str_replace(str_replace('][0][value', '[0][value]', $key), $error);
seems it should be:
form_set_error(str_replace('][0][value', '[0][value]', $key), $error);
i couldn't use it until i made this edit,
thanks again,
Joseph
Comment #3
ticici CreditAttribution: ticici commentedthanks!
also used your quick fix, changed a bit.. (cause i had some other error messages that were lost this way..)
Comment #4
fonant CreditAttribution: fonant commentedWould be nice to fix this in the date module, so it doesn't have to be fixed in every Form API form that uses a date field.
I get three "field is required" errors, and then the top-level date field error message, which is the only one that's really needed.
Comment #5
ExTexan CreditAttribution: ExTexan commentedSo, is the maintainer of the date module reading these posts (and another one that links to this issue)? Why don't you fix the date module?
Comment #6
DamienMcKennaWe're sorry but the D6 release of Date module is no longer being supported. You are encouraged to update to Drupal 7 or 8, or direct questions to Drupal Answers.