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.

Customising the CMS /

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

Reuse a userform


Go to End


6 Posts   3198 Views

Avatar
GertThiel

Community Member, 7 Posts

22 January 2009 at 11:42pm

Edited: 22/01/2009 11:57pm

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:

<?php

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 LandingPage.ss looks like:

<div id="content" class="typography">
  $Content
  $Form
<% control Kontaktformular %>
  $Content
  $Form
<% end_control %>
</div>

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?

Regards,

Gert

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

Avatar
GertThiel

Community Member, 7 Posts

25 January 2009 at 2:46am

I couldn't help myself yet :-(

Avatar
GertThiel

Community Member, 7 Posts

27 January 2009 at 4:03am

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

Avatar
GertThiel

Community Member, 7 Posts

27 January 2009 at 9:50pm

I still need help regarding this.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

28 January 2009 at 5:06am

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.

Avatar
hive.net.au

Community Member, 40 Posts

14 December 2012 at 2:00pm

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
http://www.clickheredigital.co.uk/blog/how-to-include-a-silverstripe-form-on-any-every-page/