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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

setCustomValidationMessage('xy') not showing, SiStr 2.4.5

Go to End



Community Member, 17 Posts

29 July 2011 at 9:17am

Edited: 29/07/2011 9:29am

Hi there,

I'm programming a custom form with it's own class. Now, I set a custom validation message but when I tab through the fields and leave the required one blank it always shows me ""this" wird benötigt" (it's german, set to de_DE).
I know that this message is set in de_DE.js as a general message for required fields, I try to have "this" properly set to the fieldname...
I'm tinkering for hours now and didn't find anything with search engines or on this forum.
Any help is appreciated!

class FormPage extends Page {
	public static $db = array(
	public static $has_one = array(

class FormPage_Controller extends Page_Controller {
	function OrderForm() {
		$myform = new GBorderForm($this, 'OrderForm');
		return $myform;

class GBorderForm extends Form {
	function __construct($controller, $name) {
		$Bestellung = new CheckboxField('Bestellung', 'Bestellung');
		$Vertriebspartner = new CheckboxField('Vertriebspartner', 'Vertriebspartner');
		$Interessent = new CheckboxField('Interessent', 'Interessent');
		$Name = new TextField('Name', 'Name');
		$Vorname = new TextField('Vorname', 'Vorname');
		$Firma = new TextField('Firma', 'Firma');
		$StrNr = new TextField('StrNr', 'StrNr');
		$PLZ = new TextField('PLZ', 'PLZ');
		$Ort = new TextField('Ort', 'Ort');
		$Telefon = new TextField('Telefon', 'Telefon');
		$Telefon->setCustomValidationMessage('Bitte Telefonnummer eingeben');
		$Email = new EmailField('Email', 'Email');
		$fields = new FieldSet($Bestellung,$Vertriebspartner,$Interessent,$Name,$Vorname,$Firma,$StrNr,$PLZ,$Ort,$Telefon,$Email);
		$actions = new FieldSet(new FormAction('submit', 'ABSENDEN'));
		$requiredFields = new RequiredFields('Telefon');
		parent::__construct($controller, $name, $fields, $actions, $requiredFields);

	function forTemplate() {
		return $this->renderWith(array(

	function submit($data, $form) {
		// TODO sanitize formvalues!
		echo $form->Fields()->dataFieldByName('Telefon')->Value();
		// send mail