Silverstripe Version:
4.0.2
Question:
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 *'),
);
kaftka
2
Yep, just need to pass the $Title as the third argument. Form fields are generally constructed like:
FormField::create($Name, $Title, $Value);
So
HiddenField::create('Url', 'Url', $Title);
// OR
HiddenField::create('Url')
->setValue($Title);
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.