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.

Form Questions /

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

Show a form in the sidebar

Go to End

4 Posts   2514 Views


Community Member, 7 Posts

24 January 2009 at 4:32am

Edited: 24/01/2009 4:33am

Seems like this shouldn't be tricky, but I haven't worked it out yet. What I'd like to do is display the form for a page (in this case, a UserDefinedForm) in the sidebar. Let's say it's a contact form we'd like to display on every page.

We'd think that this might work:

<% control Page(contact) %>
<% end_control %>

It doesn't - it only displays the Content of the contact page. The reason for this is that the model object is returned from Page(), but Form is a method of the controller. That makes sense, really. It's sort of weird to be getting a display from the model.

However, that's what we're expected to do here, for some reason, because that's what the Page controller method returns. Would it make more sense if it returned a controller object of some kind? Or should the Form display be passed through the model as well (seems messy to me!).

This is a problem others have had: - Newsletter Signup in Sidebar - How to add a "Subscribe Form" into the another page

I have two questions (because my hunch is the answers are different):
1. What's the way to get this to work?
2. What's the cleanest architecture to allow this behavior?



Community Member, 216 Posts

1 July 2014 at 10:39am

I see this is a really old post, but has anybody got this to work?

While I can make this happen using the silverstripe-enquiry-page module (which can be edited via the CMS) I can't as yet, see a way to make forms happen on two different page types (ie one in the sidebar on the homepage and another more detailed form on the main contact page). So it would be great to be able to do a simple form without modifying silverstripe-enquiry-page and possibly breaking it (my programming skills are limited!)


Community Member, 344 Posts

1 July 2014 at 8:11pm

That is because of <% with $Page('contact') %> will only get you the model of the Page 'contact'. You can't get a method of Page_Controller this way.

IMO: The proper way to do anything in a sidebar would be to use the module Widgets.


Community Member, 216 Posts

3 July 2014 at 4:21pm

Thanks for your feedback Devlin. I've been delving into tutorials about Silverstripe forms to try to get a more compete understanding of the topic. Unfortunately however most of my experiments ended with the 'white screen of death' (500 error)!

Anybody know of a really good Silverstripr form tutorial that explains the topic to non-programmers? While I can use the silverstripe-enquiry-page module and get a CMS-editable form complete with CAPTCHA, it would still be great to know how forms actually work in SS!