Callback Functions

Ayesha Akhtar
Ayesha Akhtar
  • Updated

Feature Snapshot

Summary:
TrustedForm Callback Functions are custom global JavaScript functions that are automatically invoked by the TrustedForm script immediately after it inserts certificate data (such as the certificate ID and certificate URL) into your forms. This allows you to trigger additional custom actions, integrations, or validations as soon as the certificate is generated.

Key Benefits:

  • Provides a hook to automatically process or log certificate data immediately after it is generated.
  • Enhances integration flexibility by allowing custom UI updates, analytics events, or lead matching actions to occur seamlessly.
  • Ensures a one‑time, predictable execution per certificate injection to avoid duplicate processing.

Typical Use Cases:

  • Displaying a pop-up or visual notification to confirm that a certificate has been generated during testing.
  • Logging certificate identifiers and URLs especially if they can not be appended to a form.

How the TrustedForm Callback Functions Work

When the TrustedForm Certify Web SDK loads on your page, it automatically looks in the global scope for specific callback functions named trustedFormCertIdCallback (for the certificate ID) and trustedFormCertUrlCallback (for the full certificate URL). If these functions are defined, the script passes the corresponding certificate data to them immediately after inserting hidden fields into your form. This process occurs only once per certificate generation, even if multiple forms exist on the page.


Step‑by‑Step Instructions

  1. Define global callback functions in your page’s JavaScript. For example:

    <script type="text/javascript">
      // Function to receive the TrustedForm Certificate ID
      function trustedFormCertIdCallback(certificateId) {
        // Custom action: alert or log the certificate ID
        alert("Certificate ID: " + certificateId);
        console.log("Received Certificate ID:", certificateId);
      }
      
      // Function to receive the full TrustedForm Certificate URL
      function trustedFormCertUrlCallback(certificateUrl) {
        // Custom action: alert or process the certificate URL
        alert("Certificate URL: " + certificateUrl);
        console.log("Received Certificate URL:", certificateUrl);
      }
    </script>
    
  2. Ensure these functions are placed in the global scope and declared before you load the TrustedForm core JavaScript snippet.

  3. Insert the TrustedForm script into your form page (typically just before the closing tag). The script will detect the previously defined callback functions and execute them immediately after generating the certificate.

  4. Customize the callback functions as needed to integrate certificate data with your lead processing systems, logging mechanisms, or UI elements.

Expected Result:
When a user loads the page, the TrustedForm script generates a certificate and immediately calls trustedFormCertIdCallback/trustedFormCertUrlCallback with the certificate data.


Validation & Monitoring (optional)

  • Test the Setup:
    Open your web page in a browser (with JavaScript enabled) and verify that the callback functions are executed—for example, by observing pop-up alerts or checking the browser’s console for the logged certificate data.

  • Where to Monitor?:
    Use your browser’s developer tools (Console and Elements panel) to ensure that the hidden certificate field (e.g., xxTrustedFormCertUrl) is populated correctly and that the callback functions are triggered only once per page load.


Best Practices

  • Always define your callback functions (trustedFormCertIdCallback and trustedFormCertUrlCallback) in the global scope before including the TrustedForm script to ensure they are detected.
  • Keep the logic inside your callbacks efficient—use lightweight actions such as logging or quick UI updates—and avoid heavy processing that could delay other page events.
  • Test your implementation in multiple browsers, and be aware that pop-up blockers or ad blockers may interfere with visual alerts; in such cases, rely on console logging for verification.
  • If integrating with other systems, ensure that the certificate data passed through the callbacks is properly sanitized and forwarded to your backend systems for further processing.

Troubleshooting

Symptom / Error Likely Cause Resolution
Callback function not executing Callback functions not defined in the global scope before the TrustedForm script loads Define trustedFormCertIdCallback (and trustedFormCertUrlCallback, if needed) in a script block placed before the TrustedForm core script in your HTML document.
No visible alert or custom action (e.g., nothing appears) Callback functions are defined but contain no visible actions or pop-ups are blocked by the browser Confirm the callback code contains executable logic (such as alert or console.log) and disable any browser pop-up blockers during testing.
Multiple callback executions occurring unexpectedly Callback functions may have been defined more than once or included in multiple scripts Ensure that each callback function is declared only once in the global scope and review the page’s script order to avoid duplications.
Certificate data appearing undefined in the callback Callback executed too early or integration order is incorrect Make sure the TrustedForm script is loaded after your callback functions are defined and that there are no conflicting scripts interfering with the data injection process.

Frequently Asked Questions (FAQ)

Q: What are TrustedForm callback functions?
A: They are custom global JavaScript functions—typically named trustedFormCertIdCallback and trustedFormCertUrlCallback—that are automatically triggered by the TrustedForm script after it inserts certificate data into your form. This allows you to perform custom actions immediately after a certificate is generated.

Q: Why are these callback functions important?
A: They let you seamlessly integrate additional processing, such as logging, UI updates, or passing lead data to other systems, immediately after the certificate is generated, thereby ensuring a smooth and automated lead capture workflow.

Q: How do I use TrustedForm callback functions?
A: Simply define your desired callback functions in the global scope before loading the TrustedForm script. In these functions, include the JavaScript logic you wish to execute when the TrustedForm certificate is generated—such as displaying alerts or sending data to your server—and then load the TrustedForm script so it can detect and invoke your callbacks.


Glossary

Term Definition
Callback Function A custom JavaScript function that is automatically executed when a specific event occurs—in this case, after the TrustedForm certificate data is injected into the form.
Certificate ID A unique identifier generated for each TrustedForm certificate which verifies the consumer’s interaction with the form.
Certificate URL The full URL pointing to the TrustedForm certificate, used to retain and later view detailed lead session data.
Global Scope The top-level context in JavaScript where functions and variables are accessible from any part of the webpage.

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.