How to Prefill Readonly Value in Form Fields

When sending out documents for signatures as a sender you might want to prefill certain form fields in the document. BoldSign provides an API that allows you to prefill form fields in the document even after sending it out for signatures.

Usually, you may not want the signer to edit the form field that you may want to prefill and lock it for editing. We can enable this by assigning the readOnly property of the form field to true. You do not need to provide a value for the form field if you want to prefill it while sending out the document. Instead, we will call another API to prefill the form field with the desired value.

The following APIs are discussed in this guide:

In this document-sending API, we will send out a document with a read-only form field. The form field is a textbox that is read-only and currently does not have a value. The form field is placed on the first page of the document at the coordinates (50, 50) with a width of 200 and a height of 30. It has an ID of FieldId. This ID will be used to prefill the form field with the desired value later.

curl --location 'https://api.boldsign.com/v1/document/send' \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: {your API key}' \
--data-raw '{
    "Title": "Document title",
    "Message": "This is a document message",
    "Signers": [
        {
            "Name": "David",
            "EmailAddress": "[email protected]",
            "formFields": [
                {
                    "Id": "FieldId",
                    "FieldType": "Textbox",
                    "PageNumber": 1,
                    "isReadOnly": true,
                    "Bounds": {
                        "X": 50,
                        "Y": 50,
                        "Width": 200,
                        "Height": 30
                    }
                }
            ]
        }
    ],
    "Files": [
        "data:application/pdf;base64,JVBERi0xLjcKJcfs..."
    ]
}'
var apiClient = new ApiClient("https://api.boldsign.com", "{your API key}");
var documentClient = new DocumentClient(apiClient);

var textField = new FormField(
    id: "FieldId",
    isReadOnly: true,
    type: FieldType.TextBox,
    pageNumber: 1,
    bounds: new Rectangle(x: 50, y: 50, width: 200, height: 30));

var signer = new DocumentSigner(
    signerName: "David",
    signerType: SignerType.Signer,
    signerEmail: "[email protected]",
    formFields: new List<FormField>() { textField },
    locale: Locales.EN);

var documentSigners = new List<DocumentSigner>()
{
    signer,
};

var sendForSign = new SendForSign()
{
    Message = "please sign this",
    Title = "Agreement",
    HideDocumentId = false,
    Signers = documentSigners,
    Files = new List<IDocumentFile>()
    {
        new DocumentFileBytes()
        {
            ContentType = "application/pdf",
            FileName = "sample.pdf",
            FileData = fileStreamArray,
        },
    },
};

var documentCreated = await documentClient.SendDocumentAsync(sendForSign);
import boldsign

configuration = boldsign.Configuration(host = "https://api.boldsign.com", api_key = "YOUR_API_KEY")

with boldsign.ApiClient(configuration) as api_client:

    document_api = boldsign.DocumentApi(api_client)

    send_for_sign = boldsign.SendForSign(
        title = "Document SDK API",
        document_title = "SDK Document Test case",
        description = "Testing document from SDK integration test case", 
        files = ["YOUR_FILE_PATH"],
        signers = [
            boldsign.DocumentSigner(
                name = "Hanky",
                emailAddress = "[email protected]",
                signerOrder = 1,
                signerType = "Signer",
                formFields = [
                    boldsign.FormField(
                        id = "FieldId",
                        fieldType = "TextBox",
                        font = "Helvetica",
                        pageNumber = 1,
                        isReadOnly = True,
                        bounds = boldsign.Rectangle(x = 50, y = 50, width = 100, height = 150)
                    )
                ],
                privateMessage = "This is private message for signer"
            )
        ]
    )

    document_created = document_api.send_document(send_for_sign)
import { DocumentApi, DocumentSigner, FormField, Rectangle, SendForSign } from "boldsign";
import * as fs from 'fs';

const documentApi = new DocumentApi("https://api.boldsign.com");
documentApi.setApiKey("YOUR_API_KEY");

const bounds = new Rectangle();
bounds.x = 50;
bounds.y = 50;
bounds.width = 200;
bounds.height = 30;

const formField = new FormField();
formField.id = "TextField1";
formField.fieldType = FormField.FieldTypeEnum.TextBox;
formField.pageNumber = 1;
formField.isReadOnly = true;
formField.bounds = bounds;

const documentSigner = new DocumentSigner();
documentSigner.name = "David";
documentSigner.emailAddress = "[email protected]";
documentSigner.signerType = DocumentSigner.SignerTypeEnum.Signer;
documentSigner.formFields = [formField];

const files = fs.createReadStream("YOUR_FILE_PATH");

const sendForSign = new SendForSign();
sendForSign.title = "Document title";
sendForSign.message = "This is a document message";
sendForSign.signers = [documentSigner];
sendForSign.files = [files];

const documentCreated = documentApi.sendDocument(sendForSign);
<?php require_once "vendor/autoload.php";

use BoldSign\Configuration;
use BoldSign\Api\DocumentApi;
use BoldSign\Model\FormField;
use BoldSign\Model\Rectangle;
use BoldSign\Model\DocumentSigner;
use BoldSign\Model\SendForSign;

$config = new Configuration();
$config->setHost('https://api.boldsign.com');
$config->setApiKey('YOUR_API_KEY');

$document_api = new DocumentApi($config);

$bounds = new Rectangle();
$bounds->setX(50);
$bounds->setY(50);
$bounds->setWidth(200);
$bounds->setHeight(30);

$form_field = new FormField();
$form_field->setId('FieldId');
$form_field->setFieldType('TextBox');
$form_field->setPageNumber(1);
$form_field->setIsReadOnly(true);
$form_field->setBounds($bounds);

$signer = new DocumentSigner();
$signer->setName('David');
$signer->setEmailAddress('[email protected]');
$signer->setSignerType('Signer');
$signer->setFormFields([$form_field]);

$send_for_sign = new SendForSign();
$send_for_sign->setTitle('Document title');
$send_for_sign->setMessage('This is a document message');
$send_for_sign->setSigners([$signer]);
$send_for_sign->setFiles(['YOUR_FILE_PATH']);

$document_created = $document_api->sendDocument($send_for_sign);
ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath("https://api.boldsign.com");
client.setApiKey("YOUR_API_KEY");

DocumentApi documentApi = new DocumentApi(client);

FormField textField = new FormField();
textField.setId("FieldId");
textField.setFieldType(FormField.FieldTypeEnum.TEXT_BOX);
textField.setPageNumber(1);
textField.setIsReadOnly(true);
Rectangle bounds = new Rectangle().x(50f).y(50f).width(200f).height(30f);
textField.setBounds(bounds);

DocumentSigner signer = new DocumentSigner();
signer.setName("David");
signer.setEmailAddress("[email protected]");
signer.setSignerType(DocumentSigner.SignerTypeEnum.SIGNER);
signer.setFormFields(Arrays.asList(textField));

SendForSign sendForSign = new SendForSign();
sendForSign.setTitle("Document title");
sendForSign.setMessage("This is a document message");
sendForSign.setFiles(Arrays.asList(new File("YOUR_FILE_PATH")));
sendForSign.setSigners(Arrays.asList(signer));

DocumentCreated documentCreated = documentApi.sendDocument(sendForSign);

We can now prefill the form fields by using the /v1/document/prefillFields API. You need to provide the document ID, form field ID, and the value that you want to prefill in the form field.

curl --location --request PATCH 'https://api.boldsign.com/v1/document/prefillFields?documentId=b5529f7e-xxxx-xxxx-xxxx-7686e52dfa8a' \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: {your API key}' \
--data '{
    "fields": [
        {
            "id": "FieldId",
            "value": "A prefilled value"
        }
    ]
}'
var apiClient = new ApiClient("https://api.boldsign.com", "{your API key}");
var documentClient = new DocumentClient(apiClient);

var documentId = "b5529f7e-xxxx-xxxx-xxxx-7686e52dfa8a";

var prefillFieldRequest = new PrefillFieldRequest(documentId)
{
    Fields = new List<PrefillField>()
    {
        new PrefillField()
        {
            Id = "FieldId",
            Value = "A prefilled value"
        }
    },
};

await documentClient.PrefillFieldsAsync(prefillFieldRequest);
import boldsign

configuration = boldsign.Configuration(host = "https://api.boldsign.com", api_key = "YOUR_API_KEY")

with boldsign.ApiClient(configuration) as api_client:

    document_api = boldsign.DocumentApi(api_client)
	
    prefill_field = boldsign.PrefillField(
        id = "FieldId",
        value = "Prefill value")
    
    prefill_field_request = boldsign.PrefillFieldRequest(fields = [prefill_field])
    
    document_api.prefill_fields(document_id = "YOUR_DOCUMENT_ID", prefill_field_request = prefill_field_request)
import { DocumentApi, PrefillField, PrefillFieldRequest } from "boldsign";

const documentApi = new DocumentApi("https://api.boldsign.com");
documentApi.setApiKey("YOUR_API_KEY");

const prefillField = new PrefillField();
prefillField.id = "FieldId";
prefillField.value = "A prefilled value";

const prefillFieldRequest = new PrefillFieldRequest();
prefillFieldRequest.fields = [prefillField];

documentApi.prefillFields("YOUR_DOCUMENT_ID", prefillFieldRequest);

<?php require_once "vendor/autoload.php";

use BoldSign\Configuration;
use BoldSign\Api\DocumentApi;
use BoldSign\Model\PrefillField;
use BoldSign\Model\PrefillFieldRequest;

$config = new Configuration();
$config->setHost('https://api.boldsign.com');
$config->setApiKey('YOUR_API_KEY');

$document_api = new DocumentApi($config);

$prefill_field = new PrefillField();
$prefill_field->setId('FieldId');
$prefill_field->setValue('A prefilled value');

$prefill_field_request = new PrefillFieldRequest();
$prefill_field_request->setFields([$prefill_field]);

$document_api->prefillFields("YOUR_DOCUMENT_ID", $prefill_field_request);
import com.boldsign.ApiClient;
import com.boldsign.Configuration;
import com.boldsign.api.DocumentApi;
import com.boldsign.model.PrefillField;
import com.boldsign.model.PrefillFieldRequest;
import java.util.Arrays;

ApiClient client = Configuration.getDefaultApiClient();
client.setBasePath("https://api.boldsign.com");
client.setApiKey("YOUR_API_KEY");

DocumentApi documentApi = new DocumentApi(client);

PrefillField prefillField = new PrefillField();
prefillField.setId("FieldId");
prefillField.setValue("A prefilled value");

PrefillFieldRequest prefillFieldRequest = new PrefillFieldRequest();
prefillFieldRequest.setFields(Arrays.asList(prefillField));

documentApi.prefillFields("YOUR_DOCUMENT_ID", prefillFieldRequest);