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.

General Questions

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

Something wrong with Form


2 Posts   686 Views


6 May 2011 at 4:57am (Last edited: 6 May 2011 4:57am), Community Member, 332 Posts

If i use the code what is attached in post and post the message from page if its default locale it works using aadress:
http://mysite/element-majad/element-b-83/?success=1 (locale is estonian)

If i use the same page in english just translated and the aadress of the page is:
but when i use the form there it redirects after sending message to

it needs to be http://mysite/standard-designs/element-b-83-en-US/?success=1 to show the page

Using code in contact from:

* Defines the Maja page type
class Maja extends Page {
static $db = array(
   'Pindala' => 'Text',
   'Tubasid' => 'Text',
   'Korruseid' => 'Text'
static $has_one = array(
   'MajaPilt' => 'Image',
   'Plaan' => 'Image',
   'Plaan2' => 'Image',
   'Plaan3' => 'Image',
   'Maja360' => 'File',
   'Spets' => 'File',
   'Spets2' => 'File'
function getCMSFields() {
$fields = parent::getCMSFields();
   $fields->addFieldToTab('Root.Content.Pilt', new ImageField('MajaPilt','Maja Pilt'));
   $fields->addFieldToTab('Root.Content.Main', new ImageField('Plaan','Esimene plaan'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new ImageField('Plaan2','Teine plaan'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new ImageField('Plaan3','Kolmas plaan'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new FileIFrameField('Maja360','Maja 360 vaade'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new FileIFrameField('Spets','Spetsi PDF'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new FileIFrameField('Spets2','2 Spetsi PDF'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new TextField('Pindala','Hoone pindala'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new TextField('Tubasid','Tubade arv'), 'Content');
   $fields->addFieldToTab('Root.Content.Main', new TextField('Korruseid','Korruste arv'), 'Content');
return $fields;

class Maja_Controller extends Page_Controller {
static $allowed_actions = array(

function MajaForm(){
$fields = new FieldSet(
new EmailField('Email', _t("FORM24.EMAIL","Teie e-post:") ),
new Textareafield('Message', _t("FORM24.MESSAGE","Teie s&otilde;num:") )
$actions = new FieldSet(new FormAction('SendMajaForm',_t("FORM24.SEND","Saada") ));
$validator = new RequiredFields(
return new Form($this, 'MajaForm', $fields, $actions, $validator);

function SendMajaForm($data, $form){
       //Set data
      $From = $data['Email'];
      $To = "";
      $Subject = "$this->Title";    
      $email = new Email($From, $To, $Subject);
      //set template
      //populate template
      //send mail
       //return to submitted message
      Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");

   //The function to test whether to display the Submit Text or not
   public function Success()
      return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";


6 May 2011 at 2:05pm Forum Moderator, 5511 Posts

You shouldn't rely on things like Director::baseURL(). $this->URLSegment. All pages (and most dataobjects) should define a Link() and an AbsoluteLink() method for getting the URL of the object.

Try something like

Director::redirect($this->Link() . "?success=1");