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
Reply

11 Posts   4404 Views

Avatar
Richie

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

<% control Page(order-form) %>
$UserDefinedForm
<% 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!

Avatar
Richie

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 %>
    $Form
    <% end_control %>

Avatar
gocreative

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\Page.ss), 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)

Cheers,

Grant

Avatar
CHD

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

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

thanks.

Avatar
JoshuaLewis

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 mysite.com/(url-segment)/finished. And to do so with the success message in place of the form.

Avatar
CHD

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?

Avatar
JoshuaLewis

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.

Avatar
MagicUK

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

Big thanks to Richie for that code!

Go to Top