Add Title of page to email from form

Silverstripe Version:


I want send a Title or URL of page, where is a form to the email… something like this: HiddenField::create(‘Url’, $Title),

Is it possible?

$fields = new FieldList( 
			HiddenField::create('Url', $Title),
			TextField::create('Name', 'Name *'),
			EmailField::create('Email', 'Email *'),
			TextField::create('Phone', 'Phone *'),

Yep, just need to pass the $Title as the third argument. Form fields are generally constructed like:

FormField::create($Name, $Title, $Value);


HiddenField::create('Url', 'Url', $Title);
// OR

Assuming you are in the PageController, you should be able to get the URL or title etc with something like:

$title = $this->Title;

// URLSegment only (from the db)
$urlSegment = $this->URLSegment;

// Full relative url:
$url = $this->getRequest()->getURL();

// full url:
$fullURL = Director::absoluteURL($this->getRequest()->getURL());

This is just an example. If the Title or URLSegment isn’t working you could try $this->data()->Title etc

Thanks $this->data()->Title etc works for me.