push(new RecaptchaField('MyRecaptcha')); } else { $fields->push(new LiteralField('
')); } $form = new Form( $this, 'Form', $fields, new FieldList( new FormAction('submit', 'submit') ), new RequiredFields(array('MyText')) ); return $form; } public function submit(array $data, Form $form): HTTPResponse { $form->sessionMessage('Hooray!', 'good'); return Director::redirectBack(); } }