How to set a checkbox field to checked and read-only by default when sending documents using API?

When sending documents for signature using the BoldSign API, you may want to set certain checkbox fields to be checked and read-only by default. This ensures that the signers cannot alter these fields during the signing process.

Pre-Checked and Read-Only by Default Checkbox Field

In the examples below, we will demonstrate how to set a Checkbox field to be pre-checked and read-only by default when sending documents for signature.

Code snippet

curl -X 'POST' \
  'https://api.boldsign.com/v1/document/send' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: {your API key}' \
  -H 'Content-Type: multipart/form-data' \
  -F 'Title="Sample Document"' \
  -F 'Signers={
  "name": "hanky",
  "emailAddress": "hankyWhites@gmail.com",
  "signerType": "Signer",
  "signerRole": "Signer",
  "formFields": [
    {
      "id": "CheckBox",
      "name": "CheckBox",
      "fieldType": "CheckBox",
      "value": "on",
      "pageNumber": 1,
      "bounds": {
        "x": 200,
        "y": 200,
        "width": 25,
        "height": 25
      },
      "isReadOnly": true
    }
  ],
  "locale": "EN"
}' \
  -F 'Files=@{your file}' \
var apiClient = new ApiClient("https://api.boldsign.com", "{Your API key}");
var documentClient = new DocumentClient(apiClient);

var documentFilePath = new DocumentFilePath
{
    ContentType = "application/pdf",
    FilePath = "{Your File path}"
};

var filesToUpload = new List<IDocumentFile>
{
    documentFilePath,
};

var checkboxField = new FormField(
    id: "CheckBox",
    type: FieldType.CheckBox,
    value: "on",
    isReadOnly: true,
    pageNumber: 1,
    bounds: new Rectangle(x: 200, y: 200, width: 25, height: 25));

var formFieldCollections = new List<FormField>()
{
    checkboxField
};

var signer = new DocumentSigner(
    signerName: "David",
    signerType: SignerType.Signer,
    signerEmail: "david@cubeflakes.com",
    formFields: formFieldCollections,
    locale: Locales.EN);

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

var sendForSign = new SendForSign()
{
    Signers = documentSigners,
    Title = "Sample Document",
    Files = filesToUpload
};
var documentCreated = documentClient.SendDocument(sendForSign);
import requests
import json

url = "https://api.boldsign.com/v1/document/send"

signer_data = {
    "name": "hanky",
    "emailAddress": "hankyWhites@gmail.com",
    "signerType": "Signer",
    "signerRole": "Signer",
    "formFields": [
    {
      "id": "CheckBox",
      "name": "CheckBox",
      "fieldType": "CheckBox",
      "value": "on",
      "pageNumber": 1,
      "bounds": {
        "x": 200,
        "y": 200,
        "width": 25,
        "height": 25
      },
      "isReadOnly": True
    }
    ],
    "locale": "EN"
}

payload = {
    'Signers': json.dumps(signer_data),
    'Title': "Sample Document"
}

files = [
    ('Files', ('{Your file name}', open('{Your file path}', 'rb'), 'application/pdf'))
]

headers = {
    'accept': 'application/json',
    'X-API-KEY': '{Your API key}'
}

response = requests.post(url, headers=headers, data=payload, files=files)

print(response.text)
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
let data = new FormData();
data.append('Signers', '{\r\n  "name": "hanky",\r\n  "emailAddress": "hankyWhites@gmail.com",\r\n  "signerType": "Signer",\r\n  "signerRole": "Signer",\r\n  "formFields": [\r\n    {\r\n      "id": "CheckBox",\r\n      "name": "CheckBox",\r\n      "fieldType": "CheckBox",\r\n      "value": "on",\r\n      "pageNumber": 1,\r\n      "bounds": {\r\n        "x": 200,\r\n        "y": 200,\r\n        "width": 25,\r\n        "height": 25\r\n      },\r\n "isReadOnly": true\r\n}\r\n  ],\r\n  "locale": "EN"\r\n}');
data.append('Files', fs.createReadStream('{Your file path}'));
data.append('Title', "Sample Document");

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.boldsign.com/v1/document/send',
  headers: { 
    'accept': 'application/json', 
    'X-API-KEY': '{Your API key}', 
    ...data.getHeaders()
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});
<?php
require_once "vendor/autoload.php";
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use \GuzzleHttp\Psr7\Utils;
$client = new Client([
    'verify' => false, // Disable SSL verification
]);
$headers = [
  'accept' => 'application/json',
  'X-API-KEY' => '{Your API Key}'
];
$options = [
  'multipart' => [
    [
      'name' => 'Signers',
      'contents' => '{
        "name": "David",
        "emailAddress": "david@boldsign.dev",
        "signerType": "Signer",
        "formFields": [
            {
                "id": "CheckBox", 
                "name": "CheckBox", 
                "fieldType": "CheckBox",
                "value": "on",
                "pageNumber": 1, 
                "bounds": {
                  "x": 200, 
                  "y": 200, 
                  "width": 25, 
                  "height": 25 
                }, 
                "isRequired": true
            }
        ], 
        "locale": "EN"
      }'
    ],
    [
      'name' => 'Title',
      'contents' => 'Sample'
    ],
    [
      'name' => 'Files',
      'contents' => Utils::tryFopen('{Your File Path}', 'r'),
      'filename' => '{Your File name}',
      'headers'  => [
        'Content-Type' => 'application/pdf'
      ]
    ]
]];
$request = new Request('POST', 'https://api.boldsign.com/v1/document/send', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();
?>

In the above code examples, set the checkbox value to on to check it and off to uncheck it. Additionally, you need to set the isReadOnly value to true to make the checkbox read-only. Upon executing the above codes, the document will be sent out for signing with the checkbox field pre-checked and unchangeable by default.