Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Translating Validation Form Error Messages

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

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

Page: 1
Go to End
Author Topic: 3513 Views
  • Turbotoast
    Avatar
    Community Member
    2 Posts

    Translating Validation Form Error Messages Link to this post

    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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Translating Validation Form Error Messages Link to this post

    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.

  • Turbotoast
    Avatar
    Community Member
    2 Posts

    Re: Translating Validation Form Error Messages Link to this post

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

    Looking forward to the next release, then!

  • erwanpia
    Avatar
    Community Member
    63 Posts

    Re: Translating Validation Form Error Messages Link to this post

    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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Translating Validation Form Error Messages Link to this post

    (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 ;)

  • erwanpia
    Avatar
    Community Member
    63 Posts

    Re: Translating Validation Form Error Messages Link to this post

    Nice method. more simple than extending UserDefinedForm, sample here

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

    3513 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.