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.

Archive /

Our old forums are still available as a read-only archive.

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

css for forms


Go to End


2 Posts   1569 Views

Avatar
lememily

Community Member, 1 Post

15 September 2008 at 8:41pm

Hi does anyone know if its possible to customize the form elements? like instead of default sumbit buttons if you can use ur own graphic. also where is the file that controls those buttons?
thanks :)

Avatar
Hamish

Community Member, 712 Posts

15 September 2008 at 9:33pm

Hi hi,

You can add classes to any Form field with the method "addExtraClass".

So, for example, you might have:

$nameField = new TextField("Name", "Name");
$nameField->addExtraClass('customNameFieldClass');

Now you can jump into any of your css files (or use Requirements::themedCSS($stylesheet) to add a new stylesheet) and apply whatever styling you like.

You can also style by ID - have a look at the generated source for the form you want to style and you'll see there is a pattern. For example, the standard login form 'name' field is called "MemberLoginForm_LoginForm_Email", so you could style by the ID if you prefer.