Jump to:

23455 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Something wrong with Form

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: 675 Views
  • Webdoc
    Community Member
    332 Posts

    Something wrong with Form Link to this post

    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 = "info@elementmajatehas.ee";
          $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";

  • Willr
    Forum Moderator
    5497 Posts

    Re: Something wrong with Form Link to this post

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

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.