Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Reuse a userform

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

Page: 1
Go to End
Author Topic: 1612 Views
  • GertThiel
    Avatar
    Community Member
    7 Posts

    Reuse a userform Link to this post

    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.

  • GertThiel
    Avatar
    Community Member
    7 Posts

    Re: Reuse a userform Link to this post

    I couldn't help myself yet

  • GertThiel
    Avatar
    Community Member
    7 Posts

    Re: Reuse a userform Link to this post

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

  • GertThiel
    Avatar
    Community Member
    7 Posts

    Re: Reuse a userform Link to this post

    I still need help regarding this.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Reuse a userform Link to this post

    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.

  • hive.net.au
    Avatar
    Community Member
    40 Posts

    Re: Reuse a userform Link to this post

    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/

    1612 Views
Page: 1
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.