Category / Section
Can I use textbox field as a name field when creating templates via BoldSign API?
Published:
1 min read
When creating templates using the BoldSign API, you can utilize the TextBox field as a Name field. The TextBox is a versatile and customizable form field that can be used to capture or display signer names, making it suitable for various use cases in both templates and documents.
How to use a textbox as a name field
- Prefill the Signer’s Name: Use the value property to dynamically set the signer’s name when sending the document.
- Make the Field Read-Only (Optional): Set isReadOnly to true if you want the name to be displayed but not editable by the signer.
- Allow Manual Entry with Validation (Optional): If you prefer the signer to enter their name manually, leave the field editable and apply a custom regex pattern to validate the input format. For more details, refer to this guide: How to add validation to the textbox form field via API?
Below is a sample code snippet to demonstrate this:
cURL
curl -X 'POST' \ 'https://api.boldsign.com/v1/template/create' \
-H 'accept: application/json' \
-H 'X-API-KEY: {your API key}' \
-H 'Content-Type: multipart/form-data' \
-F 'Files=@Bill-of-Sale.pdf;type=application/pdf' \
-F 'Title=title of the template' \
-F 'Description=testingDescription' \
-F 'DocumentTitle=title of the document' \
-F 'Roles={
"Name": "Hr",
"Index": 1,
"DefaultSignerName": "Alex Gayle",
"DefaultSignerEmail": "alexgayle@cubeflakes.com",
"SignerOrder": 1,
"SignerType": "Signer",
"FormFields": [
{
"Id": "NameField",
"name": "Name",
"FieldType": "TextBox",
"isReadOnly": true,
"PageNumber": 1,
"Bounds": {
"X": 50,
"Y": 100,
"Width": 100,
"Height": 60
},
"IsRequired": true
"value": "John Doe"
}
]
}'
.Net
var apiClient = new ApiClient("YOUR_API_KEY");
var templateClient = new TemplateClient(apiClient);
List<FormField> formField = new List<FormField>
{
new FormField(
id: "NameField",
name: "Name",
type: FieldType.TextBox,
isReadOnly: true,
pageNumber: 1,
bounds: new Rectangle(x: 100, y: 100, width: 150, height: 25),
isRequired: true,
value: "John Doe"
)
};
var templateRequest = new CreateTemplateRequest
{
Title = "Agreement",
DocumentTitle = "title of the document",
Roles =
[
new TemplateRole()
{
Index = 1,
Name = "HR",
DefaultSignerName = "David",
DefaultSignerEmail = "david@cubeflakes.com",
SignerType = SignerType.Signer,
FormFields = formField
}
],
Files = new List<IDocumentFile>
{
new DocumentFilePath
{
ContentType = "application/pdf",
FilePath = "YOUR_FILE_PATH",
}
},
};
var templateCreated = templateClient.CreateTemplate(templateRequest);
Python
import boldsign
configuration = boldsign.Configuration(api_key="YOUR_API_KEY")
with boldsign.ApiClient(configuration) as api_client:
template_api = boldsign.TemplateApi(api_client)
form_field = boldsign.FormField(
id="NameField",
name="Name",
fieldType="TextBox",
isReadOnly=True,
page_number=1,
bounds=boldsign.Rectangle(x=100, y=100, width=150, height=25),
isRequired=True,
value="John Doe"
)
role = boldsign.TemplateRole(
index=1,
name="Hr",
defaultSignerName="Alex Gayle",
defaultSignerEmail="alexgayle@boldsign.dev",
signerType="Signer",
formFields=[form_field]
)
create_template_request = boldsign.CreateTemplateRequest(
title="title of the template",
documentTitle="title of the document",
roles=[role],
files=["YOUR_FILE_PATH"]
)
template_created = template_api.create_template(create_template_request=create_template_request)
PHP
<?php
require_once "vendor/autoload.php";
use BoldSign\Configuration;
use BoldSign\Api\TemplateApi;
use BoldSign\Model\{FormField, Rectangle, TemplateRole, CreateTemplateRequest};
$config = new Configuration();
$config->setApiKey('YOUR_API_KEY');
$template_api = new TemplateApi($config);
$form_field = new FormField();
$form_field->setId('NameField');
$form_field->setName('Name');
$form_field->setFieldType('TextBox');
$form_field->setIsReadOnly(true);
$form_field->setIsRequired(true);
$form_field->setValue('John Doe');
$form_field->setPageNumber(1);
$bounds = new Rectangle([100, 100, 150, 25]);
$form_field->setBounds($bounds);
$role = new TemplateRole();
$role->setIndex(1);
$role->setName('HR');
$role->setDefaultSignerName('Alex Gayle');
$role->setDefaultSignerEmail('alexgayle@boldsign.dev');
$role->setSignerType('Signer');
$role->setFormFields([$form_field]);
$create_template = new CreateTemplateRequest();
$create_template->setTitle('Document SDK API');
$create_template->setDocumentTitle('title of the document');
$create_template->setRoles([$role]);
$create_template->setFiles(['YOUR_FILE_PATH']);
$template_created = $template_api->createTemplate([$create_template]);
Java
ApiClient client = Configuration.getDefaultApiClient();
client.setApiKey("YOUR_API_KEY");
TemplateApi templateApi = new TemplateApi(client);
FormField nameField = new FormField();
nameField.setId("NameField");
nameField.setName("Name");
nameField.setFieldType(FormField.FieldTypeEnum.TEXTBOX);
nameField.setIsReadOnly(true);
nameField.setIsRequired(true);
nameField.setValue("John Doe");
nameField.setPageNumber(1);
Rectangle bounds = new Rectangle().x(100f).y(100f).width(150f).height(25f);
nameField.setBounds(bounds);
TemplateRole templateRole = new TemplateRole();
templateRole.setIndex(1);
templateRole.setName("Hr");
templateRole.setDefaultSignerName("Alex Gayle");
templateRole.setDefaultSignerEmail("alexgayle@boldsign.dev");
templateRole.setSignerType(TemplateRole.SignerTypeEnum.SIGNER);
templateRole.setFormFields(Arrays.asList(nameField));
CreateTemplateRequest createTemplate = new CreateTemplateRequest();
createTemplate.setTitle("title of the template");
createTemplate.setDocumentTitle("title of the document");
createTemplate.setRoles(Arrays.asList(templateRole));
File file = new File("YOUR_FILE_PATH");
createTemplate.setFiles(Arrays.asList(file));
TemplateCreated templateCreated = templateApi.createTemplate(createTemplate);
Node.js
import { TemplateApi, CreateTemplateRequest, TemplateRole, Rectangle, FormField } from "boldsign";
import * as fs from "fs";
const templateApi = new TemplateApi();
templateApi.setApiKey("Your API Key");
const bounds = new Rectangle();
bounds.x = 100;
bounds.y = 100;
bounds.width = 150;
bounds.height = 25;
const formField = new FormField();
formField.id = "NameField";
formField.name = "Name";
formField.fieldType = FormField.FieldTypeEnum.TextBox;
formField.pageNumber = 1;
formField.bounds = bounds;
formField.isRequired = true;
formField.isReadOnly = true;
formField.value = "John Doe";
const role = new TemplateRole();
role.index = 1;
role.name = "Signer";
role.defaultSignerEmail = "alex@cubeflakes.com";
role.defaultSignerName = "Alex Gayle";
role.signerType = TemplateRole.SignerTypeEnum.Signer;
role.formFields = [formField];
const file = fs.createReadStream("Your File path.pdf");
const createTemplateRequest = new CreateTemplateRequest();
createTemplateRequest.title = "Testing node sdk";
createTemplateRequest.documentTitle = "Node sdk test case";
createTemplateRequest.roles = [role];
createTemplateRequest.files = [file];
async function createTemplate() {
try {
const response = await templateApi.createTemplate(createTemplateRequest);
console.log("Template Created:", response);
} catch (error) {
console.error("Error creating template:", error.response?.data || error.message || error);
}
}
createTemplate();