src/Tasks/PopulateThemeSampleDataTask.php
protected function createContactForm()
    {
        $form = UserDefinedForm::create(array(
            'Title' => 'Contact',
            'URLSegment' => 'contact',
            'Content' => '<p>$UserDefinedForm</p>',
            'SubmitButtonText' => 'Submit',
            'ClearButtonText' => 'Clear',
            'OnCompleteMessage' => "<p>Thanks, we've received your submission and will be in touch shortly.</p>",
            'EnableLiveValidation' => true
        ));

        $form->write();

        // Add form fields
        $fields = array(
            EditableFormStep::create([
                'Title' => _t(
                    'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFormStep.TITLE_FIRST',
                    'First Page'
                )
            ]),
            EditableTextField::create([
                'Title' => 'Name',
                'Required' => true,
                'RightTitle' => 'Please enter your first and last name'
            ]),
            EditableEmailField::create([
                'Title' => Email::class,
                'Required' => true,
                'Placeholder' => 'example@example.com'
            ]),
            EditableTextField::create([
                'Title' => 'Subject'
            ]),
            EditableTextField::create([
                'Title' => 'Message',
                'Required' => true,
                'Rows' => 5
            ])
        );

        foreach ($fields as $field) {
            $field->write();
            $form->Fields()->add($field);
            $field->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
        }

        $form->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
        $form->flushCache();

        $this->output(' + Created "contact" UserDefinedForm page');

        return $this;
    }
protected function createContactForm()
    {
        $form = UserDefinedForm::create(array(
            'Title' => 'Contact',
            'URLSegment' => 'contact',
            'Content' => '<p>$UserDefinedForm</p>',
            'SubmitButtonText' => 'Submit',
            'ClearButtonText' => 'Clear',
            'OnCompleteMessage' => "<p>Thanks, we've received your submission and will be in touch shortly.</p>",
            'EnableLiveValidation' => true
        ));

        $form->write();

        // Add form fields
        $fields = array(
            EditableFormStep::create([
                'Title' => _t(
                    'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFormStep.TITLE_FIRST',
                    'First Page'
                )
            ]),
            EditableTextField::create([
                'Title' => 'Name',
                'Required' => true,
                'RightTitle' => 'Please enter your first and last name'
            ]),
            EditableEmailField::create([
                'Title' => Email::class,
                'Required' => true,
                'Placeholder' => 'example@example.com'
            ]),
            EditableTextField::create([
                'Title' => 'Subject'
            ]),
            EditableTextField::create([
                'Title' => 'Message',
                'Required' => true,
                'Rows' => 5
            ])
        );

        foreach ($fields as $field) {
            $field->write();
            $form->Fields()->add($field);
            $field->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
        }

        $form->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
        $form->flushCache();

        $this->output(' + Created "contact" UserDefinedForm page');

        return $this;
    }
protected function createContactForm ( ) { $ form = UserDefinedForm :: create ( array ( 'Title' => 'Contact' , 'URLSegment' => 'contact' , 'Content' => '<p>$UserDefinedForm</p>' , 'SubmitButtonText' => 'Submit' , 'ClearButtonText' => 'Clear' , 'OnCompleteMessage' => "<p>Thanks, we've received your submission and will be in touch shortly.</p>" , 'EnableLiveValidation' => true ) ) ; $ form -> write ( ) ; // Add form fields $ fields = array ( EditableFormStep :: create ( [ 'Title' => _t ( 'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFormStep.TITLE_FIRST' , 'First Page' ) ] ) , EditableTextField :: create ( [ 'Title' => 'Name' , 'Required' => true , 'RightTitle' => 'Please enter your first and last name' ] ) , EditableEmailField :: create ( [ 'Title' => Email :: class , 'Required' => true , 'Placeholder' => 'example@example.com' ] ) , EditableTextField :: create ( [ 'Title' => 'Subject' ] ) , EditableTextField :: create ( [ 'Title' => 'Message' , 'Required' => true , 'Rows' => 5 ] ) ) ; foreach ( $ fields as $ field ) { $ field -> write ( ) ; $ form -> Fields ( ) -> add ( $ field ) ; $ field -> copyVersionToStage ( Versioned :: DRAFT , Versioned :: LIVE ) ; } $ form -> copyVersionToStage ( Versioned :: DRAFT , Versioned :: LIVE ) ; $ form -> flushCache ( ) ; $ this -> output ( ' + Created "contact" UserDefinedForm page' ) ; return $ this ; }
Create a "contact us" userform. Please note that this form does not have any recipients by default, so
no emails will be sent. To add recipients - edit the page in the CMS and add a recipient via the "Recipients"
tab.

@return $this
Create a contact us userform . Please note that this form does not have any recipients by default so no emails will be sent . To add recipients - edit the page in the CMS and add a recipient via the Recipients tab .