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.

All other Modules

Discuss all other Modules here.

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

User forms: Show $UserDefinedForm inside Page(url-segment)

Go to End

11 Posts   4416 Views


29 August 2009 at 12:31am (Last edited: 29 August 2009 12:33am), Community Member, 18 Posts

<% control Page(order-form) %>
<% end_control %>

I also tried $Form but both with no result. $Content gives the value of the content field ($UserDefinedForm) instead of the user form.
Do I have to create a custom method for this?

Any ideas? Thanks!


3 September 2009 at 2:33am Community Member, 18 Posts

I added this function to the Page class

   function ShowForm(){
      $get = DataObject::get_one('SiteTree', "URLSegment = 'order-form'");
      return new UserDefinedForm_Controller($get);

And inside my template

    <% control ShowForm %>
    <% end_control %>


14 May 2010 at 12:09am Community Member, 17 Posts

Hi guys,

This has been really helpful. The only problem is, when I added the code to my template file (\themes\mytheme\templates\Layout\, it adds the form to every page of the site. How do I set the form to only show on a particular page?

(This is my first SS installation so please forgive my ignorance)




23 September 2010 at 5:33am Community Member, 218 Posts

This is AWESOME.
and useful for lots of other features, not just forms :)



30 September 2010 at 9:17am (Last edited: 30 September 2010 9:17am), Community Member, 76 Posts

The next question is how to make the form reload the same page after submission instead of And to do so with the success message in place of the form.


1 October 2010 at 3:43am Community Member, 218 Posts

thats a good question...

also, i would like a hidden field on the form that generates the page title (e.g - $Title) so that i know which page/category the form was submitted via.

does anybody know how i can do this?
i took a look at the template files for userform, but it looks a bit more complex than i was hoping.

i figured i could just add:

<input type="hidden" name="Page" value="$Title" />

to the template...but where?


1 October 2010 at 6:09am (Last edited: 1 October 2010 6:09am), Community Member, 76 Posts

The redirect is coming from line756 of userforms/code/UserDefinedForm.php at the end of the process() method of UserDefinedForm_Controller.

The best solution I have right now is to subclass UserDefinedForm and overwrite process() keeping everything the same except for that last line which gets replaced with whatever logic is needed, possibly even a call to another method. This is a kludge though so if anyone has a solution that doesn't involve recreating process() in its entirety I'd love to hear it.


26 July 2011 at 9:36pm Community Member, 60 Posts

Big thanks to Richie for that code!

Go to Top