1793 Posts in 589 Topics by 561 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1205 Views |
-
Returning current page in email about submitted form

25 January 2009 at 10:08pm
Hi guys, I have a simple form which appears on every product page of a site, I would like it so that when the form is submitted the title of the page on which the form is submitted from appears in the email. How can this be done? Here is the current code for the form. Thanks in advance for any help!
function ContactForm() {
// Create fields
$fields = new FieldSet(
new EmailField('Email'),
new TextareaField('Message')
);// Create actions
$actions = new FieldSet(
new FormAction('doContact', 'Submit')
);
$validator = new RequiredFields('Email', 'Message');
return new Form($this, 'ContactForm', $fields, $actions, $validator);
}function doContact($data, $form) {
$email = new Email();
$email->setTemplate('ContactPage_Email');
$email->setSubject('Someone submitted the contact form');
$email->setFrom('admin@somesite.com');
$email->setTo('howardgrigg@gmail.com');
$email->populateTemplate($data);
$email->send();$form->sessionMessage('Thanks for contacting us. We will endeavour to get in touch with you as soon as possible!', 'good');
Director::redirectBack();
} -
Re: Returning current page in email about submitted form

25 January 2009 at 11:30pm
Hey, thanks to ajshort in the IRC chatroom I have got this working, I just needed to pass the Title into the data array and then call it in the email template. The new code is posted below:
function doContact($data, $form) {
$data['PageName'] = $this->Title;
$email = new Email();
$email->setTemplate('ContactPage_Email');
$email->setSubject('Someone submitted the contact form');
$email->setFrom('admin@jdmnz.com');
$email->setTo('howardgrigg@gmail.com');
$email->populateTemplate($data);
$email->send();$form->sessionMessage('Thanks for contacting us. We will endeavour to get in touch with you as soon as possible!', 'good');
Director::redirectBack();
} -
Re: Returning current page in email about submitted form

5 February 2009 at 10:41pm
Hi!
I read your post, I have a question for you.
I have a problem if I send data schoose from checkboxsetField. I have this error:ArrayData::__construct: Parameter needs to be an object or associative array
At line 39 in E:\_silverstripe_cms\silverstripe\sapphire\core\ArrayData.phpnew CheckboxSetField(
$name = "topics",
$title = "Settori d'interesse:",
$source = array(
"1" => "Information Management",
"2" => "Application Integration (EAI)",
"3" => "System Management",
),
$value = ""
)and in GenericEmail.ss I wrote: Settori d'interesse: $topics
Have you idea how solve this?
Thanks!!
| 1205 Views | ||
|
Page:
1
|
Go to Top |

