Reputation: 4424
I am working on a custom email form that should be able to handle the following URLs:
http://www.example.com/email
Defaults to general email address.
http://www.example.com/email/Office/1
Gets email contact details from Office model, ID 1
http://www.example.com/email/Staff/96
Gets email contact details from Staff model, ID 96
I thought I could do this by accessing the normal $Action/$ID variables - but got utterly confused by the Routing documentation: https://docs.silverstripe.org/en/3.3/developer_guides/controllers/routing/
class EmailPage_Controller extends Page_Controller
{
private static $allowed_actions = array(
'Form',
'Staff',
'Office'
);
public function Form() {
$Action = $this->request->getVar('Action');
$ID = $this->request->getVar('ID');
Doesn't work.
What's the best way of accessing/ passing URL variables to a form in Silverstripe?
Upvotes: 4
Views: 851
Reputation: 89
$ID = $this->request->param('ID');
This will get you the id from the Url parameters as you have defined them in your routes or $url_handlers.The same method is used to get the action parameter.
Upvotes: 5