Silverstripe’s nice form builder, in its current version, has one big drawback : it doesnot handle translations very well. Coming from a discussion on Silverstripe’s forums, I have decided to manage my own translation solution for UserDefinedForms.
The idea is to extend the UserDefinedForm pagetype to let it accept an additional field to handle language information.
- in cms/code/PageTypes/UserDefinedForm.php, modify the UserDefinedForm class definition :
static $db = array(
“EmailTo” => “Varchar”,
“EmailOnSubmit” => “Boolean”,
“SubmitButtonText” => “Varchar”,
“OnCompleteMessage” => “HTMLText”,
“Language” => “Varchar”
- add the input field in the main tab in getCMSFields function :
$fields->addFieldToTab(“Root.Content.Main”, new TextField( ‘Language’,'Language (fr, en, ar)’));
local/test.js : var global_validation_message=”Please fill out this field”;
local/fr.js : global_validation_message=”Veuillez renseigner ce champ”;
replace var errorMessage = “Please fill out \”$FieldLabel\”, it is required.”;
with var errorMessage=global_validation_message;