Include userform on page

Silverstripe Version: 4.2

How do I include a userform i have created on page.php?
In silverstripe 3 i used to use the below code in the pageContoller but it no longer works in SS4.
I know that UserDefinedForm_Controller is now UserDefinedFormController but i still get errors

function ShowForm(){ 
        $get = DataObject::get_one('SiteTree', "URLSegment = 'contact-us'"); 
        return new UserDefinedForm_Controller($get); 
    }

Please post the errors you’re getting

Not too clear on the end goal here, but your ShowForm() method appears to be returning a controller rather than just a form, is that what you want?

You could try ModelAsController::controller_for($siteTreeObject)->Form()

1 Like

Thanks JonoM. Your solution worked when I wanted to reuse a UserDefinedForm

I’m also trying to do something similar. In SS3 I was simply able to subclass the user forms page type to have the form appear within a page.

Worked nicely, but with upgrade to SS4.2.1, the form will work fine until I run the next dev/build, then page containing forms appears ‘modified’ in CMS and loses all its form fields. Inspecting the database via phpmyadmin, I can see that all the parent classes get reset for the EditableFormFields and UserDefinedForm_EmailRecipients.

Not quite sure whether I’m using it wrong or it’s a bug?