21294 Posts in 5734 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 500 Views |
-
Something wrong with Form

6 May 2011 at 4:57am Last edited: 6 May 2011 4:57am
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:
http://mysite/standard-designs/element-b-83-en-US/
but when i use the form there it redirects after sending message to
http://mysite/element-b-83-en-US/?success=1it needs to be http://mysite/standard-designs/element-b-83-en-US/?success=1 to show the page
Using code in contact from:
<?php
/**
* 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(
'MajaForm'
);function MajaForm(){
$fields = new FieldSet(
new EmailField('Email', _t("FORM24.EMAIL","Teie e-post:") ),
new Textareafield('Message', _t("FORM24.MESSAGE","Teie sõnum:") )
);
$actions = new FieldSet(new FormAction('SendMajaForm',_t("FORM24.SEND","Saada") ));
$validator = new RequiredFields(
'Message',
'Email'
);
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
$email->setTemplate('MajaEmail');
//populate template
$email->populateTemplate($data);
//send mail
$email->send();
//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";
}
}
?> -
Re: Something wrong with Form

6 May 2011 at 2:05pm
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");
| 500 Views | ||
|
Page:
1
|
Go to Top |


