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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

[SOLVED] Custom Form productpage needs to send Title of product with e-mail

Go to End

3 Posts   1237 Views


Community Member, 3 Posts

28 October 2011 at 9:36pm


I have edited product.php and added a simple contact form from, so on every product page there is a contact form.
The only problem is that i want the product title (and mayby some other variables like price etc) to send with the e-mail.
Im trying this by adding the product title to the value of a textfield and sending this textfield with the email.
The fields are sending the data that is inserted, expect the variable title(its not showing in the textfield). I dont really know how to add this variable to the form/data. Any help would be great.

Here is the code that I've added to product.php:

class Product_Controller extends Page_Controller {

static $allowed_actions = array(

function ReageerForm() {
// Create fields
$fields = new FieldSet(
new TextField('Title', 'Title', $value = $Title),
new TextField('Bedrijfsnaam', 'Bedrijfsnaam'),
new TextField('Naam', 'Naam'),
new EmailField('Email', 'Email'),
new TextField('Telefoon', 'Telefoon'),
new TextField('Onderwerp', 'Onderwerp'),
new TextareaField('Bericht','Bericht')

// Create action
$actions = new FieldSet(
new FormAction('SendReageerForm', 'Verzenden')

// Create Validators
$validator = new RequiredFields('Naam', 'Telefoon', 'Onderwerp', 'Bericht', 'Email');

return new Form($this, 'ReageerForm', $fields, $actions, $validator);


function SendReageerForm($data, $form, $title) {

//Set data
$From = $data['Email'];
$To = $this->Mailto;
$To = "";
$Subject = "Reactie Product";
$email = new Email($From, $To, $Subject);
//set template
//populate template
//send mail
//return to submitted message

Thank you in advance for the help you can provide.


Community Member, 215 Posts

29 October 2011 at 10:38am

Hi JanJan - welcome to the forum.

The way that usually solve this is by using a hidden field in the form like this:

function ContactForm() {

		if($currentPage = DataObject::get_by_id("SiteTree", $this->ID)){

		$fields = new FieldSet(
			new TextField('Name'),
			new EmailField('Email'),
			new TextareaField('Message'),
			new HiddenField ('Page', 'Page',
		$actions = new FieldSet( new FormAction('doContactForm', 'Submit'));
		$validator = new RequiredFields('Email', 'Message');

		return new Form($this, 'ContactForm', $fields, $actions, $validator);

Then in your email template you can just use $Page to display the title of the page that the form was displayed on.

Does that help?


Community Member, 3 Posts

2 November 2011 at 12:13am

Hi Howard,

Thank you for your quick reply!
The information you have provided me was enough and has helped me to solve my problem.
The if($currenpage) statement is what i needed for my contact form.

Thank you again for you help!