Creating a Page When a Form is Submitted

Creating a new page from a form submission is useful if form responses require a follow-up or collaborative action, for example, if a user submits an internal feature request or events proposal. If you have Script Runner for Confluence installed, you can run a script on the “FormSubmitEvent” that creates a new Confluence page when a form is submitted. 


  1. Create a new Form that includes input fields to collect a specified Space Key, Page Title and Page Content.

    You can include additional fields such as a parent page or Forms Attachment macro if needed.

    Placeholders indicating a new Form macro containing 2 Input Field macros, a Textarea Field macro, and an attachment.

  2. Configure the Event Listener for FormsSubmitEvent, where the spaceKeypageTitle, and pageContent correspond to the name parameter defined for the macros in your form. When the form is submitted, a new page is created with the values entered by the user.
    Event listener configuration screen.

import com.atlassian.confluence.core.DefaultSaveContext
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.xwork.FileUploadUtils
import groovy.json.JsonSlurper
try {
    String event = ((HashMap<String, String>) binding.variables).get("event").structuredValue
    Map<String, String> data = new JsonSlurper().parseText(event)
    List<FileUploadUtils.UploadedFile> uploadedFiles = ((HashMap<String, String>) binding.variables).get("event").uploadedFiles
    def pageManager = ComponentLocator.getComponent(PageManager)
    def spaceManager = ComponentLocator.getComponent(SpaceManager)
    def spaceKey = data.get("spaceKey")[0]
    def pageTitle = data.get("pageTitle")[0]
    def pageContent = data.get("pageContent")[0]
    def targetPage = new Page(
        space: spaceManager.getSpace(spaceKey),
        title: pageTitle,
        bodyAsString: pageContent,
    pageManager.saveContentEntity(targetPage, DefaultSaveContext.DEFAULT)
} catch (anyException) {
    log.warn("Failed to create page for new user", anyException)

FormsSubmitEvent in Action

Using our example script and form, when the form is submitted, a new page is created in the DW (Documentation) space in Confluence titled Who is in/out, with the Request details displayed in the page body. Users can then comment on, share, update, or action this page as needed.

Saved and rendered Form example.

Example of the new page created when the form is submitted.