I’m using 2.4.7 and I want to include some validation for two fields which take in prices (e.g. €1 or 2 for €3). Originally I thought that perhaps I would need to resort to validating user input but as the answer suggests it was a database issue.
The encoding within SilverStripe was defaulting to ASCII which converted the symbols such as the euro symbol. In the end I need to add
$this->response->addHeader("Content-Type", "application/json; charset='utf-8'");
to the init method in the controller. This corrected the encoding issue and prevented a hacky workaround taking place. Many thanks for the insight on this one.
Thanks
I’m assuming you want to do this in the CMS. If that’s the case, the easiest way is probably to create a new class which extends the
TextFieldclass and adds apublic function validate()method which performs your validation (see the CreditCardField class for an example).Once you’ve created your class, you can modify the form fields in your
getCMSFields()function on theDataObjectand use the new class in place ofTextField.Having said that, it feels like output encoding and not input validation is the root cause of your problem. I’d check to make sure that everything is setup to use UTF-8.