Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Translating Validation Form Error Messages


Go to End


6 Posts   4249 Views

Avatar
Turbotoast

Community Member, 2 Posts

24 June 2008 at 7:38pm

Edited: 24/06/2008 7:38pm

Hey there everyone,

I'm trying to build my first Silverstripe site and I'm quite content with it, yet I have stumbled upon a problem that I was not able to solve yet.

I've created a contact form and drag-and-dropped all fields that I want, and it works like a charm, with a tiny problem: If the user focuses, say, an email field and then focuses another (or submits the form without filling in his email), I get the message:

"Please fill in Deine Email-Adresse, it is required"

Not something that will get my customer happy, I'm afraid.
I took a short glimpse, and this error message seems to be hard coded into the sapphire core.

Anyone got an idea of how to change this without hacking away at the core code or setting up my own contact form?

Regards,
Jörn

Avatar
Ingo

Forum Moderator, 801 Posts

28 June 2008 at 6:26pm

form validation is being improved for the 2.3 release, which is unfortunately still a while away.
one of the bulletpoints here is to make localization easier in both client- and serverside.
you might want to have a look at our development plan: http://open.silverstripe.com/wiki/development/validation

for now, you'd have to overload the javascript in Validator.js and subclass RequiredFields.php.

Avatar
Turbotoast

Community Member, 2 Posts

1 July 2008 at 11:46pm

Works like a charm, although it's a bad hack, thank you lots!

Looking forward to the next release, then!

Avatar
erwanpia

Community Member, 63 Posts

19 July 2008 at 8:31pm

hi

if 2.3 form translation feature is a while away,

can anyone post a sample of how to translate validation messages properly for forms

Avatar
Ingo

Forum Moderator, 801 Posts

22 July 2008 at 11:20pm

(in your controller php code):
Requirements::customScript("Behaviour.register({'#MyForm': { initialise: function() { this.requiredErrorMsg = 'Bitte füllen Sie das Feld $FieldLabel aus';}});

no guarantee on right bracketing, just wrote it down... $FieldLabel is automatically replaced in javascript. Have a look through Validator.js, you can customize this on a field-by-field level as well. Having custom validation messages e.g. for EmailField gets a bit trickier, the easiest way is to subclass the FormField instance.

Its a pain in the ass, we're working on it ;)

Avatar
erwanpia

Community Member, 63 Posts

23 July 2008 at 3:52pm

Nice method. more simple than extending UserDefinedForm, sample here

http://www.webmasterbulletin.net/2008/07/silverstripe-form-validation-translation/78