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

Custom form template, error message for server side validation

Go to End

4 Posts   4795 Views


Community Member, 80 Posts

24 June 2009 at 12:49pm

I have read the following doc It works 99% percent the way I wanted. What I would like to know is that, is there more documentation on how to customize the form template. You see, in the example given from above link, only contain two 'text' input filed, what happen if I need dropdown, radio, textarea etc, I would think it needs something like, $dataFieldByName('dropDownName'). I will try them out, but more documentation would be very helpful here.

Second, even though I manage to get this simple form up and running, one thing I found is that if I turn the javascript off, the server side validation seems work all right by not letting script proceed any further, yet, the error message does not show anywhere on the page, some thing is off.

Any advice would be appreciated, I am running out of time.

Thank you.


Community Member, 712 Posts

24 June 2009 at 1:29pm

Edited: 24/06/2009 1:30pm

To add new form elements you just keep adding them to the fields array:

function MyCustomForm() {
	$fields = new FieldSet(
		new EmailField("Email"),
		new EncryptedField("Password"),
		new DropdownField("Foo1", "Bar1"),
		new CheckboxField("Foo2", "Bar2"),
	$actions = new FieldSet(new FormAction("login", "Log in"));
	return new Form($this, "MyCustomForm", $fields, $actions);

This page might be more useful to you:

Most likely, you have not created the form action that handles the form response, or your form action does not return anything to the user via a template.

In the above example, you need to have a 'login' method in the controller of the page where the form is located. This login method should return a template, or redirect to another page.

Please supply you code (preferable via and I can have a closer look at the issue.


Community Member, 80 Posts

24 June 2009 at 2:10pm

Hi Hamish

Thank you for your reply. I have posted my code on Here is the link:

I am aware of these doc you mentioned. I know how to add different type of input into the form, what I am not certain is how to display them in my custom template. Most important, I can't get server side validation error message to be displayed on my custom template.

Thanks again!


Community Member, 36 Posts

10 December 2009 at 8:29pm

I know it has been a while, but here:
<span class="message $dataFieldByName(CreditCardNumber).MessageType">$dataFieldByName(CreditCardNumber).Message</span>