pardotFormHandlerJS
is a script tailored for setting up custom Pardot (aka "Marketing Cloud Account Engagement") forms on your website without using iframes or backend APIs, as it sends requests directly from browser to Pardot handler.
Project is lightweight and doesn't have any dependencies, effort was made to not add any unnecessary "fluff". It was attempted to support old browsers, without overdoing it. Suggestions and reports are welcome. There was no AI slavery on this project.
https://MindaugasPaulauskas.github.io/pardotFormHandlerJS/
https://github.com/MindaugasPaulauskas/pardotFormHandlerJS/tree/main/demo/
- Add
pardot-form-handler-js.min.js
to your project.- for example:
<script src="https://yourwebsite.com/path-to-scripts/pardot-form-handler-js.min.js"></script>
.
- for example:
- Add callback scripts to your server, callback scripts can be dynamic or static:
- Option A (recommended): setup dynamic callback script as it's documented in
pardot-form-callback-dynamic.js-examples
directory, example of scripts location:https://yourwebsite.com/path-to-scripts/pardot-form-callback-dynamic.js
- Option B (not recommended as error messages from Pardot are lost, default error message will be shown): upload
pardot-form-callback-error.js
andpardot-form-callback-success.js
scripts to your server to be accessed within your website, for example:https://yourwebsite.com/path-to-scripts/pardot-form-callback-error.js
andhttps://yourwebsite.com/path-to-scripts/pardot-form-callback-success.js
.
- Option A (recommended): setup dynamic callback script as it's documented in
- Edit Chosen Pardot Form Handlers Success and Error Locations to the one you have set up before.
- update Success Location, for example:
https://yourwebsite.com/path-to-scripts/pardot-form-callback-success.js
. - update Error Location, for example:
https://yourwebsite.com/path-to-scripts/pardot-form-callback-dynamic.js
.
- update Success Location, for example:
- Edit Chosen Pardot Form Handlers Form Fields:
- create Form Fields corresponding to your form inputs (or form values in the case of an ajax call).
- for every field choose
External Field Name
that corresponds to html form input names. - for every field write an appropriate
Error Message
, so it could be understood in the error message, as all errors get joined to a single message.
Create an html form with action to your Pardot form handler location and add initialize it with code:
let pardotFormDom = document.querySelector(".your-form-elements-selector");
let pardotForm = window.pardotFormHandlerJS.setupForm(pardotFormDom);
Success and error messages will appear on top of the form, if you want messaging to be placed in a different location, within your form, create a container with class pardot-form-handler-js--message-container.
You can set up multiple forms on the page.
If you are choosing to use provided AJAX functionality, probably you have done some similar work before as there is some extra work involved.
Utility functions |
---|
pardotFormHandlerJS.getFormValues() |
pardotFormHandlerJS.setupForm(form[, settings])
Returns a PardotForm object
- form is the dom object of the form that will submit to Pardot
- settings is an object with initial settings to be set. Read more in Settings parameter object at the end of this documentation. (Settings also can be set later via setSettings method)
PardotForm.setSettings(settings)
Sets the settings for the Pardot form.
Returns a PardotForm object.
- settings is an object with settings to be set. Read more in Settings parameter object at the end of this documentation.
PardotForm.onBeforeSubmit(callbackFunction)
PardotForm.onBeforeSubmit(function(formValues, form){/* yourcode goes here */})
Returns a PardotForm object.
- callbackFunction is a function to be executed just before the submission, allowing code to terminate submission if needed.
- formValues is an object with form values.
- form is a DOM element for referencing the form.
return
false
to terminate the submissionreturn
true
orvoid
to process submission with originalformValues
return
modiffiedformValues
to continue with the submission
- to do local validation
- to add hidden form values before sumbission
- to do an asyncronious actions (includes usage of pause() and unpause())
PardotForm.pause()
Returns a PardotForm object.
- used in tandem with unpause() function, to pause submission for asyncronious process
- call the function after onBeforeSubmit() is called and before callback function (callbackFunction) returns value;
- to do validation in an api
- to to a CAPTCHA chalenge
PardotForm.unpause(formValues)
Returns a PardotForm object.
- formValues
- set
formValues
asfalse
to terminate the submission - set
formValues
astrue
orvoid
to process submission with currentformValues
- set
formValues
as modiffiedformValues
to continue with the submission with .
- used in tandem with pause() function, to pause submission for asyncronious process, it unpauses the submission
- call the function after asyncronious process completes
- to unpause the paused form (pausing reasons are listed in pause() functions section)
- to add hidden form values before sumbission
PardotForm.onSubmit(callbackFunction)
PardotForm.onSubmit(function(detail){/* your code goes here */})
Returns a PardotForm object.
- callbackFunction is a function to be executed just after the submission.
- detail is an object submission and result details. In this case the result is not available.
- to lock form
- to show loader
- to remove old error messages
PardotForm.onCancel(callbackFunction)
PardotForm.onCancel(function(detail){/* your code goes here */})
Returns a PardotForm object.
- callbackFunction is a function to be executed when a new form submission is made on the same form and the current request has not yet completed.
- detail is an object submission and result details. In this case the result is not available.
PardotForm.onSuccess(callbackFunction)
PardotForm.onSuccess(function(detail){/* your code goes here */})
Returns a PardotForm object.
- callbackFunction is a function to be executed when form submission is completed successfully.
- detail is an object submission and result details.
- to show custom success messaging
- to replace the form with success message
- to send form data to your database through an api call
PardotForm.onError(callbackFunction)
PardotForm.onError(function(detail){/* your code goes here */})
Returns a PardotForm object.
- callbackFunction is a function to be executed when form submission is completed and has errors or timeouts.
- detail is an object submission and result details.
- to show custom error messaging
PardotForm.onComplete(callbackFunction)
PardotForm.onComplete(function(detail){/* your code goes here */})
Returns a PardotForm object.
- callbackFunction is a function to be executed after the submission has completed (after success or error).
- detail is an object submission and result details.
- to unlock form
- to remove/hide loader
PardotForm.destroy()
Call this function to remove event listeners and cancel the current request of the Pardot form.
create an object with settings that you want to change, for example:
{
successMessage: "Thank you!",
timeout: 9999,
defaultErrorMessage: "Something Went Wrong! Please try again.",
}
- actionUrl:
false
, - successMessage:
"Success! Thank you for submission."
, - resetFormAfterSuccess:
true
, - defaultErrorMessage:
"Submission failed! Please enter required information."
, - timeout:
5000
, - timeoutMessage:
"Oops! Request has timed out. Please try again later."
, - showLoadingOverlay:
true
, - loadingOverlayBgColor:
"rgba(0,0,0,0.1)"
, - loadingOverlayInnerHtml: [long string with html code, too long to display here],
- showFormMessaging:
true
, - messageErrorBgColor:
"#dd1a21"
, - messageErrorTxtColor:
"#fff"
, - messageSuccessBgColor:
"#147f3c"
, - messageSuccessTxtColor:
"#fff"
, - messagePadding:
"4px"
, - messageMargin:
"0 0 4px"
, - messageBorderRadius:
"4px"
.
let pardotDebugForm = window.pardotFormHandlerJS.setupForm(
document.querySelector("#pardot-debug-form"),
{successMessage: "Success!", loadingOverlayBgColor: "rgba(255,255,255,0.5)"}
)
.setSettings({
successMessage: "More Success!",
})
.onBeforeSubmit(function(formValues, form) {
console.log("[onBeforeSubmit] formValues:", formValues);
// Example code for pausing the submission.
console.log("[pause]");
pardotDebugForm.pause();
setTimeout(() => {
console.log("[unpause]");
pardotDebugForm.unpause();
}, 1000);
})
.onSubmit(function(detail) {
console.log("[onSubmit] detail:", detail);
})
.onCancel(function(detail) {
console.log("[onCancel] detail:", detail);
})
.onSuccess(function(detail) {
console.log("[onSuccess] detail:", detail);
})
.onError(function(detail) {
console.log("[onError] detail:", detail);
})
.onComplete(function(detail) {
console.log("[onComplete] detail:", detail);
});
pardotDebugForm.setSettings({
successMessage: "Even more Success!",
});
pardotFormHandlerJS.ajax(url, values[, settings])
Returns an AJAX object
- url is a string of a Pardot url that ajax call is going to submit to
- values is an object with the values that are going to be submitted to Pardot
- settings is an object with settings to be set. Read more in Settings parameter object at the end of this documentation.
AJAX.onSubmit(callbackFunction)
AJAX.onSubmit(function(detail){/* your code goes here */})
Returns an AJAX object.
- callbackFunction is a function to be executed just after the submission.
- detail is an object submission and result details. In this case the result is not available.
- to lock form
- to show loader
- to remove old error messages
AJAX.onSuccess(callbackFunction)
AJAX.onSuccess(function(detail){/* your code goes here */})
Returns an AJAX object.
- callbackFunction is a function to be executed when form submission is completed successfully.
- detail is an object submission and result details.
- to show custom success messaging
- to replace the form with success message
- to send form data to your database through an api call
AJAX.onError(callbackFunction)
AJAX.onError(function(detail){/* your code goes here */})
Returns an AJAX object.
- callbackFunction is a function to be executed when form submission is completed and has errors or timeouts.
- detail is an object submission and result details.
- to show custom error messaging
AJAX.onComplete(callbackFunction)
AJAX.onComplete(function(detail){/* your code goes here */})
Returns an AJAX object.
- callbackFunction is a function to be executed after the submission has completed (after success or error).
- detail is an object submission and result details.
- to unlock form
- to remove/hide loader
create an object with settings that you want to change, for example:
{
successMessage: "Thank you!",
timeout: 9999,
defaultErrorMessage: "Something Went Wrong! Please try again.",
}
- actionUrl:
false
, - successMessage:
"Success! Thank you for submission."
, - defaultErrorMessage:
"Submission failed! Please enter required information."
, - timeout:
5000
, - timeoutMessage:
"Oops! Request has timed out. Please try again later."
.
pardotFormHandlerJS.ajax(
"https://pardothandler.onrender.com/pardot-handler-simulation-with-dynamic-success-and-error-location",
{name: "Mindaugas", email: "fake@email.io"},
{successMessage: "You have subscribed!", timeoutMessage: Something went wrong. Please try again later."}
)
.onSubmit(function(detail) {
console.log("[onSubmit] detail:", detail);
})
.onSuccess(function(detail) {
console.log("[onSuccess] detail:", detail);
})
.onError(function(detail) {
console.log("[onError] detail:", detail);
})
.onComplete(function(detail) {
console.log("[onComplete] detail:", detail);
});
pardotFormHandlerJS.getFormValues(form)
Returns an object with form values.
- form is a Dom object of a form.
Usefull to get all form values, especialy when using AJAX functionality.
- More documentation is coming (especially on configuration)
- More demos are coming (open to suggestions)
- Please report any issues
- This project was "uninspired" by https://github.com/horans/pardot-form-ajax-handler
- Code minification has been done using https://skalman.github.io/UglifyJS-online/
hashCode
function was taken from https://stackoverflow.com/questions/194846/is-there-hash-code-function-accepting-any-object-type/#answer-8076436
- GitHub corner code taken from https://tholman.com/github-corners/
- SweetAlert2 popup: https://sweetalert2.github.io
- tingle.js popup: https://tingle.robinparisi.com
- Pardot form mockup handler and dynamic callback server is hosted on https://render.com free plan
- Static demo files are hosted on https://pages.github.com
- GitHub star button on demo page hosted on https://ghbtns.com
- SweetAlert2 script and styles are hosted on: https://www.jsdelivr.com
- tingle.js script and styles are hosted on: https://tingle.robinparisi.com