Skip to content

Signature Requests JavaScript API

The Signature Requests JavaScript library embeds signature request forms on your website for collecting electronic signatures. It was called Data Requests JS until version 3.0.0, which renamed its function and options (see the changelog).

Creates an embedded signing form for collecting electronic signatures.

DocSpring.createSignatureRequestForm(cssSelector, optionsAndCallbacks);
// or
DocSpring.createSignatureRequestForm(optionsAndCallbacks);
ParameterTypeRequiredDescription
cssSelectorstringNoCSS selector for the container element where the form will be rendered
optionsAndCallbacksobjectYesConfiguration options and event callbacks
OptionTypeDescription
signatureRequestIdstringYour signature request ID
tokenIdstringYour Token ID
tokenSecretstringYour Token Secret

You can pass signatureRequestURL instead of these three options.

OptionTypeDefaultDescription
redirectURLstringnullRedirect to this URL after submitting the form (overrides the template’s redirect URL)
redirectURLQueryParamsbooleantrueAutomatically add submission_id, template_id, and template_name query params to the redirect URL
focusFirstFieldOnLoadbooleanfalseAutomatically focus the first field after the form is loaded
showSignatureModalOnFocusbooleanfalseAutomatically open the signature/initials popup when a signature or initials field is focused
closeModalOnClickOverlaybooleantrueAllow the user to close the form by clicking on the modal overlay
closeModalOnSavebooleanfalseClose the modal after the form has been saved
closeModalOnProcessedbooleanfalseClose the modal after the PDF has been processed
loadingTimeoutnumber30000Milliseconds to wait for the signing form to load before calling onError with a load_timeout error
showClearButtonbooleantrueShow the “Clear Form” button
showTermsOfServiceLinkbooleantrueShow a link to DocSpring’s terms of service on the “Accept Terms” screen
allowSkippingOptionalFieldsbooleannullSet to true to show the “Continue” button as soon as every required field is filled in, without first going through each optional field with “Next”. Set to false to always go through the optional fields. Overrides the template’s “Show Continue Once Required Fields Are Filled In” setting, which is used when this is null (Requires version 2.6.0 or above)
termsOfServiceLabelstring"DocSpring Terms of Service"Label for the terms of service link
termsOfServiceURLstringDocSpring ToSURL for the terms of service link
downloadButtonLabelstring"Download PDF"Change the download button label
showDeclinebooleantrueShow the “Decline” button in the form header. Set to false to hide it. (Requires version 2.4.0 or above. Older versions never show the button)
declineButtonLabelstring"Decline"Change the label of the “Decline” button shown in the form header (e.g. "Cancel - Do Not Sign")
showPdfProcessingSpinnerbooleantrueShow a spinner while the PDF is being processed
iframeClassstringnullCSS class for the iframe element
iframeStylestringnullInline styles for the iframe element
footerHTMLstring or functionnullCustom HTML content for the footer. A function receives the template object
signatureRequestURLstringnullFull authenticated signature request URL. Only used when signatureRequestId, tokenId, and tokenSecret are not all provided. Its origin is used to verify messages from the iframe
regionstringUSUse a DocSpring region: US or EU
hoststringnullUse one host for both app and API URLs, usually for single-domain enterprise deployments
appHoststringnullOverride the app host used for the signing iframe, usually for split-domain enterprise deployments
apiHoststringnullOverride the API host used by the visual form inside the signing iframe

Use region when your account is in the EU region:

Regional signature request
DocSpring.createSignatureRequestForm({
signatureRequestId: 'srq_123456',
tokenId: 'tok_123456',
tokenSecret: 'secret_123456',
region: 'EU'
})

For single-domain enterprise deployments, use host. For split-domain deployments, use appHost and apiHost. Existing globals such as DocSpring.region, DocSpring.appHost, DocSpring.apiHost, DocSpring.host, DocSpring.scheme, and DocSpring.port are still supported. If you pass signatureRequestURL without signatureRequestId, tokenId, and tokenSecret, that full URL is used for the iframe and to verify messages from the iframe.

Customize the titles and messages shown in the header. These options can be either a plain string or a function that returns a string.

OptionFunction ArgumentsDescription
signatureLegalDisclaimerMessagetemplate (object)Legal disclaimer text shown below the signature pad when signing
agreeToTermsTitletemplate (object), formData (object)Title for the “Agree to terms of service” step
agreeToTermsMessagetemplate (object), formData (object)Message for the “Agree to terms of service” step
waitingForSignatureRequestsTitleremainingSignatureRequestsCount (number), template (object)Title when there are still pending signature requests
waitingForSignatureRequestsMessageremainingSignatureRequestsCount (number), template (object)Message when there are still pending signature requests
submittingTitletemplate (object)Title when the data is being submitted
submittingMessagetemplate (object)Message when the data is being submitted
pdfProcessingTitletemplate (object)Title when the PDF is being processed
pdfProcessingMessagetemplate (object)Message when the PDF is being processed
completedTitletemplate (object), downloadURL (string)Title when the PDF has been processed
pdfProcessedMessagetemplate (object), downloadURL (string)Message when the PDF has been processed
completedTitleNoDownloadtemplate (object)Title when data is saved but no download URL is available
CallbackParametersDescription
onInitialize-Called when the form has been initialized
onLoad-Called when all form pages have been loaded
onClearForm-Called after the clear button is pressed and the form is cleared
onFieldFocus{ id, name, value }Called when a field gains focus
onFieldBlur{ id, name, value }Called when a field loses focus
onFieldChange{ id, name, value, previousValue }Called when a field value changes
onShowAcceptTerms-Called when the user clicks “Continue” to show the final “Accept Terms” screen
onDecline-Called when the user declines to sign. The signature request and its submission are cancelled, and no PDF is generated
onSubmitformData (object)Called when the submit button is pressed
onSave{ submissionId }Called when the form has been saved
onProcessed{ submissionId, downloadURL }Called when the PDF has been processed (only if “Submission Privacy” is “Public”). If the form redirects, the redirect follows one second later, even if closeModalOnProcessed closes the modal (from version 2.5.0; older versions don’t call it when the form redirects)
onRemainingSignatureRequestsremainingSignatureRequestsCountCalled when other signature requests still need to be filled in (only if “Submission Privacy” is “Public”). If the form redirects, the redirect follows one second later, unless the page closes the form first (for example to show the next signer’s form)
onError{ error, message }Called when something goes wrong, with an error code and a message (see Errors)

onError gets an object with an error code and a message to show or log. A failed save or decline also has the response’s HTTP status.

errorWhen
frame_blockedThe browser refused to show the signing form. A live signature request only loads on the sites in the template’s Embed Domains setting (see Embedded Signature Requests)
token_expiredThe signing link has expired: an api token works for 24 hours and an email token for 7 days. Create a new token
invalid_tokenThe token ID or secret is wrong, or the token is for another signature request
not_foundThe signature request doesn’t exist
signature_request_completedThe signer has already signed
signature_request_declinedThe signature request was declined
submission_expiredThe document was deleted
save_failedSaving the signer’s values failed
decline_failedDeclining failed
processing_failedThe PDF couldn’t be generated
processing_timeoutThe PDF is taking more than a minute to generate. Sent once: the form keeps waiting for it
load_timeoutThe signing form didn’t load within loadingTimeout
message_timeoutThe signing form didn’t confirm a message from your page
internal_errorSomething went wrong on our side when the signing form opened
unknown_errorAnything else

Data Requests JS (before 3.0.0) passes a string, or nothing when the PDF couldn’t be generated.

These global functions allow you to interact with the form. If a page opens more than one form, they act on the most recently opened form that is still open (from version 2.5.0).

FunctionParametersDescription
DocSpring.clearForm()-Clear all data on the form and reset to default values
DocSpring.focusNextField()-Focus the next field (same as clicking “Next” button)
DocSpring.focusField(name_or_id)name_or_id: Field name or numeric IDFocus a specific field
DocSpring.returnToForm()-Return to the form after it has been submitted
DocSpring.closeModal()-Close every signature request form shown in a modal
Basic signature request form
DocSpring.createSignatureRequestForm({
signatureRequestId: 'srq_123456',
tokenId: 'tok_123456',
tokenSecret: 'secret_123456'
})
Signature request with options
DocSpring.createSignatureRequestForm('.form-container', {
// Required options
signatureRequestId: 'srq_123456',
tokenId: 'tok_123456',
tokenSecret: 'secret_123456',
// UI customization
downloadButtonLabel: 'Get My Document',
showSignatureModalOnFocus: true,
// Callbacks
onSubmit: function(formData) {
console.log('Form submitted:', formData);
},
onProcessed: function(data) {
console.log('PDF ready:', data.downloadURL);
},
onError: function(error) {
console.error('Error:', error.error, error.message);
}
})
Custom footer buttons
DocSpring.createSignatureRequestForm({
signatureRequestId: 'srq_123456',
tokenId: 'tok_123456',
tokenSecret: 'secret_123456',
footerHTML: function(template) {
return '<div class="dsp-footerLeft">' +
'<button class="dsp-button dsp-primaryButton" onclick="customSave()">Save Draft</button>' +
'</div>' +
'<div class="dsp-footerRight">' +
'<button class="dsp-button" onclick="customCancel()">Cancel</button>' +
'</div>';
}
})
Custom messages
DocSpring.createSignatureRequestForm({
signatureRequestId: 'srq_123456',
tokenId: 'tok_123456',
tokenSecret: 'secret_123456',
// Custom messages
signatureLegalDisclaimerMessage: 'By signing, I agree to the terms.',
agreeToTermsTitle: function(template, formData) {
return 'Please Review and Sign ' + template.name;
},
completedTitle: function(template, downloadURL) {
return 'Your ' + template.name + ' is Ready!';
},
pdfProcessedMessage: 'Your document has been generated successfully.'
})

Enable debug logging to troubleshoot issues:

DocSpring.DEBUG = true;

This will show extra debugging log messages in the developer console. If you are experiencing any problems with your integration, please enable logging and include the console logs in your support request.

The Signature Requests JavaScript library supports all modern browsers:

  • Chrome 60+
  • Firefox 55+
  • Safari 11+
  • Edge 79+

Older versions of Internet Explorer are not supported.