Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » User forms: Show $UserDefinedForm inside Page(url-segment)

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 4257 Views
  • Richie
    Avatar
    Community Member
    18 Posts

    User forms: Show $UserDefinedForm inside Page(url-segment) Link to this post

    <% 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!

  • Richie
    Avatar
    Community Member
    18 Posts

    Re: User forms: Show $UserDefinedForm inside Page(url-segment) Link to this post

    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 %>

  • gocreative
    Avatar
    Community Member
    17 Posts

    Re: User forms: Show $UserDefinedForm inside Page(url-segment) Link to this post

    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

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: User forms: Show $UserDefinedForm inside Page(url-segment) Link to this post

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

    thanks.

  • JoshuaLewis
    Avatar
    Community Member
    76 Posts

    Re: User forms: Show $UserDefinedForm inside Page(url-segment) Link to this post

    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.

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: User forms: Show $UserDefinedForm inside Page(url-segment) Link to this post

    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?

  • JoshuaLewis
    Avatar
    Community Member
    76 Posts

    Re: User forms: Show $UserDefinedForm inside Page(url-segment) Link to this post

    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.

  • MagicUK
    Avatar
    Community Member
    60 Posts

    Re: User forms: Show $UserDefinedForm inside Page(url-segment) Link to this post

    Big thanks to Richie for that code!

    4257 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.