Adding Form Fields

This guide will demonstrate how to add new form fields.

Before you begin

You should get your API key from your UniCloud account.

If this is your first time using UniOffice SDK, follow this guide to set up a local development environment.

Clone the project repository

In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.

git clone https://github.com/unidoc/unioffice-examples

Navigate to the path document/form-fields folder in the unioffice-examples directory.

cd unioffice-examples/document/form-fields

How it works

Lines 4-10 import the UniOffice packages and other required dependencies.

The init function in lines 12-19 authenticates your request with your UNIDOC_LICENSE_API_KEY.

The main function creates a new document and a paragraph within it, where a new checkbox is added and its properties are assigned in lines 27-31. Next, a new paragraph is created, adding a text input with its respective characteristics in lines 35-37. Finally, the same process is carried out to add a dropdown list in lines 41-44.

Finally, all Form Fields are collected, displayed on the screen, and the new document is saved.

Run the code

Run this command to create a document with the form fields:

go run main.go

Sample output

found 3 fields
- Name: checkbox1 Type: FormFieldTypeCheckBox Value: true
- Name: textInput1 Type: FormFieldTypeText Value: Hello World
- Name: Solar system Type: FormFieldTypeDropDown Value: Earth

Adding Form Fields

Got any Questions?

We're here to help you.