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.

Form Questions /

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

setCustomValidationMessage('xy') not showing, SiStr 2.4.5


Go to End


1817 Views

Avatar
Gutur

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(
			$this->class,
			'Form'
		));
	}

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