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.

Customising the CMS

Reuse a userform


6 Posts   1631 Views


22 January 2009 at 11:42pm (Last edited: 22 January 2009 11:57pm), Community Member, 7 Posts

Dear fellow SilverStripe users,

I've got trouble reusing a form: I have a "contact us" page created using the userforms module (SilverStripe 2.3.0-rc2). This works as intended. This particular "contact us" page shall now be reused on —meaning inserted at the bottom of— several landing pages including the actual contact form which had been defined in the CMS.

My LandingPage.php looks like:


class LandingPage extends Page {
static $db = array();
static $has_one = array(
'Kontaktformular' => 'UserDefinedForm'

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TreeDropdownField('KontaktformularID', 'Bitte wählen Sie eine Kontaktseite aus, die am Ende dieser Seite eingeblendet werden soll', 'SiteTree'), 'Content');
return $fields;


class LandingPage_Controller extends Page_Controller {}


And my looks like:

<div id="content" class="typography">
<% control Kontaktformular %>
<% end_control %>

But SilverStripe prints the $Content of Kontaktformular (the referenced "contact us" page) only. The $Form inside <% control Kontaktformular %> returns nothing. So the (userforms) form is missing!

Do you have an idea what I did wrong?



I tried $has_one = array('Kontaktformular' => 'Page') and $has_one = array('Kontaktformular' => 'SiteTree') as well. But that didn't help at all.


25 January 2009 at 2:46am Community Member, 7 Posts

I couldn't help myself yet :-(


27 January 2009 at 4:03am Community Member, 7 Posts

I couldn't help myself yet :-(
Will I ever get an answer?


27 January 2009 at 9:50pm Community Member, 7 Posts

I still need help regarding this.


28 January 2009 at 5:06am 4085 Posts

Sadly, I don't think this is going to work. My guess is that the Form() function for that module is in the controller, not the model -- with good reason. The form needs to post to its own controller to process. So even if you could do it, you'd have a form using $this as a controller, which at that time would be the current page that has no idea how to handle the form and it would choke.

Best advice to you is create your own form and have Page_Controller handle it, or some other central place. Custom forms are much easier to work with anyway. Though i've never used the Userform module, my guess is, if it's anything like the old UserDefinedForm type in SS 2.2, it's simply not built for modular deployment like you're trying to do.


14 December 2012 at 2:00pm Community Member, 40 Posts

For future reference this works like a charm if anyone is after a solution.

Its so simple when you think about it.

Thanks for the tip click here digital