Reputation: 49
I need some help with converting SS3 to SS4. I would like to render my contact form on another page as well as my default Contact page. I managed to get it working in SS3 but things are a little different in SS4 and I am not sure how to write the function or where to put it. I have tried a bunch of combinations and locations but I need help.
In SS3 I created my UserDefineForm page with its fields. I then added the following to the custom page that I wanted the form to render too:
class IndexPage_Controller extends Page_Controller {
// Sign up form
public function SignupForm(){
$get = DataObject::get_one('SiteTree', "URLSegment = 'contact-me'");
return new UserDefinedForm_Controller($get);
}
}
What/Where do I put the function in SS4 to get the form fields to render on the custom page template as it does on the Contact us page?
Thank you in advance.
Upvotes: 0
Views: 354
Reputation: 337
The code below should work.
public function getSignupForm()
{
$page = \SilverStripe\UserForms\Model\UserDefinedForm::get()->filter('URLSegment', 'contact-me')->first();
$controller = \SilverStripe\UserForms\Control\UserDefinedFormController::create($page);
return $controller->Form();
}
Upvotes: 1