21287 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 718 Views |
-
Add contact form to Page

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 -
Re: Add contact form to Page

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.
-
Re: Add contact form to Page

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);
...
| 718 Views | ||
|
Page:
1
|
Go to Top |

