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 forum.silverstripe.org 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.

All other Modules /

Discuss all other Modules here.

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

Nesting UserDefinedForm on parent page


Go to End


2 Posts   899 Views

Avatar
Apc204

Community Member, 12 Posts

28 March 2015 at 12:46am

Edited: 28/03/2015 12:47am

I have a client wishing to be able to add custom forms to pages they create in the CMS. I figured the best way to do this would be to use the UserDefinedForm module, and allow them to create the form as a child page. I then planned on showing the form at the bottom of the template if it existed by doing something like:

<% loop $Children %>
$Form
<% end_loop %>

But this doesn't seem to work as I cannot access $Form from the parent page. Has anyone found a way around this, or does the module simply not support embedding the forms on another page?

Thanks in advance,
Adam.

Avatar
Pyromanik

Community Member, 419 Posts

28 March 2015 at 2:27am

Children gets you Pages, which are Models.
Forms are on Controllers, as they must process requests.

Add to the model:

public function Form() {
	$controller = ModelAsController::controller_for($this);
	return $controller->hasMethod('Form') ? $controller->Form() : null;
}

You can do this either through Extension (in which case you'll need to use $this->owner) or by subclassing (in which case you'll need to update the page type of your form pages in the cms).