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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Add contact form to Page


Go to End


4 Posts   1382 Views

Avatar
Webdoc

Community Member, 349 Posts

10 March 2011 at 1:24pm

How to add translateable fields names to form on somepage.php or in somepage.ss
let say that the fields are simple like subject with Value=$title of page
email and message and also the submit button must be translatable.

i know that i need to use <% _t("Name","Name:") %> in .ss file
but how to use translatable in .php and what lines i need u but in the lang file if i wanna let say translate fieldname "name" from mysite/somepage.php

Avatar
Webdoc

Community Member, 349 Posts

10 March 2011 at 1:26pm

and also what code i need to use in .php fail that i takes the page tilte and but it into subject of forms email.

Avatar
Webdoc

Community Member, 349 Posts

10 March 2011 at 2:41pm

Can somone plz help

Avatar
martimiz

Forum Moderator, 1391 Posts

11 March 2011 at 1:43am

I'm not quite sure what it is you're aiming at, but maybe this will help some?

If you are building a custom form on your website (and not the UserForms module) using a ContactForm() method in your page controller, adding a translatable label goes the same way as with the CMSfields:

function ContactForm() {

	$fields = new FieldSet(
		new TextField(
		'Name',
		_t('ContactPage.NAME','Name')
	),
	...

If you were to use a custom form template, where you'd indeed define your labels, use <% _t('ContactPage.NAME','Name')) %>. Make sure there is no whitespace after the comma...

Then add the translation to your languagefile xx_XX.php, like

$lang['xx_XX]['MyContactPage']['Name'] = 'translated name';

If you use <% _t('NAME','Name')) %> (without the ContactPage namespace) SilverStripe will automatically use the template name, so for ContactPage.ss, you'd have to put this in your language file:

$lang['xx_XX]['ContactPage.ss']['Name'] = 'translated name';

However, this doesn't always work well with nested templates so take care.

(make sure the correct locale is set for your page)

Getting your page title into the subject (still assuming you're using a custom form) You'd do something like this in you 'submit' method:

function doSubmit($postedData, $form){

	...
	$Email = new Email();
	$Email->setSubject($this->Title);
	...