Skip to content

Data Requests JavaScript API

The Data Requests JavaScript library allows you to embed signing forms on your website for collecting electronic signatures.

Creates an embedded signing form for collecting electronic signatures.

DocSpring.createVisualForm(cssSelector, optionsAndCallbacks);
// or
DocSpring.createVisualForm(optionsAndCallbacks);
ParameterTypeRequiredDescription
cssSelectorstringNoCSS selector for the container element where the form will be rendered
optionsAndCallbacksobjectYesConfiguration options and event callbacks
OptionTypeDescription
dataRequestIdstringYour Data Request ID
tokenIdstringYour Token ID
tokenSecretstringYour Token Secret
OptionTypeDefaultDescription
defaultFormDataobject{}Default data to fill in the fields (can be modified by the user)
staticFormDataobject{}Static data to fill in the fields (cannot be modified by the user)
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
waitForPDFbooleantrueIf redirectURL is provided, set to false to redirect immediately instead of waiting for PDF processing
domainVerificationbooleantrueSet to false during development to disable domain verification
focusFirstFieldOnLoadbooleanfalseAutomatically focus the first field after the form is loaded
showSignatureModalOnFocusbooleanfalseAutomatically open the signature popup when a signature field is focused
closeModalOnClickOverlaybooleantrueAllow the user to close the form by clicking on the modal overlay
showTermsOfServiceLinkbooleantrueShow a link to DocSpring’s terms of service on the “Accept Terms” screen
downloadButtonLabelstring"Download PDF"Change the download button label
showPdfProcessingSpinnerbooleantrueShow a spinner while the PDF is being processed
iframeClassstringnullCSS class for the iframe element
iframeStylestringnullInline styles for the iframe element
footerHTMLstringnullCustom HTML content for the footer

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
waitingForDataRequestsTitleremainingDataRequestsCount (number), template (object)Title when there are still pending data requests
waitingForDataRequestsMessageremainingDataRequestsCount (number), template (object)Message when there are still pending data 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
onSubmitformData (object)Called when the submit button is pressed
onSavesubmissionIdCalled when the form has been saved
onProcessed{ submissionId, downloadUrl }Called when the PDF has been processed (only if “Submission Privacy” is “Public”)
onRemainingDataRequestsremainingDataRequestsCountCalled when other data requests still need to be filled in
onErrorerrorCalled if there is an error with the request

These global functions allow you to interact with the form. Note that only one DocSpring form can be displayed on a page.

FunctionParametersDescription
DocSpring.clearForm()-Clear all data on the form and reset to default values
DocSpring.submitForm()-Submit the form. Validation errors will be displayed if present
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.setField(name_or_id, value)name_or_id: Field name or numeric ID
value: Value to set
Set the value for a specific field
DocSpring.closeModal()-Close and hide the data request modal
Basic data request form
DocSpring.createVisualForm({
dataRequestId: 'drq_123456',
tokenId: 'tok_123456',
tokenSecret: 'secret_123456'
})
Data request with options
DocSpring.createVisualForm('.form-container', {
// Required options
dataRequestId: 'drq_123456',
tokenId: 'tok_123456',
tokenSecret: 'secret_123456',
// Prefill data
defaultFormData: {
name: 'John Smith',
},
// Static data that can't be changed
staticFormData: {
company: 'Acme Corp'
},
// Redirect after completion
redirectURL: 'https://example.com/thank-you',
waitForPDF: false,
// 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);
}
})
Custom messages
DocSpring.createVisualForm({
dataRequestId: 'drq_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 data requests library supports all modern browsers:

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

Older versions of Internet Explorer are not supported.