5121 Posts in 1527 Topics by 1119 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1242 Views |
-
Reuse a userform

22 January 2009 at 11:42pm Last edited: 22 January 2009 11:57pm
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. -
Re: Reuse a userform

27 January 2009 at 4:03am
I couldn't help myself yet
Will I ever get an answer? -
Re: Reuse a userform

28 January 2009 at 5:06am
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.
-
Re: Reuse a userform

14 December 2012 at 2:00pm
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/
| 1242 Views | ||
|
Page:
1
|
Go to Top |


