Jump to:

23013 Posts in 11540 Topics by 2825 members

General Questions

SilverStripe Forums » General Questions » Add contact form to Page

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

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

Page: 1
Go to End
Author Topic: 857 Views
  • Webdoc
    Avatar
    Community Member
    329 Posts

    Add contact form to Page Link to this post

    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

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: Add contact form to Page Link to this post

    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.

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: Add contact form to Page Link to this post

    Can somone plz help

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: Add contact form to Page Link to this post

    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);
       ...

    857 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.