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've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Getting extra data to a form while using DataObjects as Page pattern?

Go to End

3 Posts   1343 Views


Community Member, 7 Posts

5 August 2016 at 6:50pm

I've set up a few different Silverstripe sites, but for the first time now I am using the DataObject as a Page pattern. I've read through the information on different ways to do this and I've run into a problem:

I've got a DataObject representing staff members and Page operating as a holding page. The page has allowed_actions for listing, searching and showing staff members, and on the show pages there is a form that allows to to send an email to a staff member.

Since the ContactFormHandler method is on the StaffHolder page controller, when it is called, it has no access to the staff object (which is normally picked up on the 'show' action) so it can't determine where to send the email.

There are a few ways I can think of to fix this:
1. Send extra url parameters to the form with the staff member ID, but I can't find anywhere in the API to achieve this.
2. There is a pushCurrent() method on Controller, which might allow me to push a new ShowStaffMember_Controller onto the controller stack and then have the FormHandler on this new controller. Not sure if this is possible though, but would love to hear if anyone has been able to do this?
3. Pass the ID through a session variable - Not ideal, but probably which way I will try first.
4. Pass the ID through a hidden field - Really don't want to do this as the email shouldn't be exposed in the form.

Wondering if anyone else has run into something like this and how they solved it?


Community Member, 49 Posts

6 August 2016 at 5:58pm

If the contact form is to send a staff member a message then having the staff member id in a hidden field makes sense.

If the StaffMemberID is in the URL params then you can use loadDataFrom:

class MyForm extends Form {
    function __construct($controller, $name) {
        parent::__construct($controller, $name, $fields, $actions);
	// populate form with url params


Community Member, 7 Posts

7 August 2016 at 6:11pm

Thanks for replying jaybee, that makes sense. If it's sent as an ID the destination email address won't be exposed in the form. I'm always hesitant to pass details that the user doesn't need (even in hidden fields), but that will work sending just the ID then lookup the DataObject in the FormAction method.

The other reason I was looking to use a seperate controller was because the StaffHolder controller is getting pretty monolithic, and starting to handle things that would be clearer if they were delegated. Any ideas how to achieve this? I've tried a few different things, but no success. It would be great if there was a clear way to do this?