When you need a place or a timing on where to put your code.
Our RCFX Pixel includes a function called onFormCapture that lets you run code when a form is submitted.
This will fire when a form is captured. Before submitting the form as an event to RCFX, we can put a code here to execute.
This is useful if you want to execute code or change the form before submitting it to RCFX.
Sample uses:
Console log the form to be submitted:
mcfx(function(t) {
t.configure("onFormCapture", function(form) {
console.log(form);
});
});
Give names to elements in the form that do not have a name:
mcfx(function(t) {
t.configure("onFormCapture", function(form) {
var customIdCounter = 1;
var elements = form.querySelectorAll('input, select, textarea');
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (!element.name) {
element.name = element.id ? element.id : 'rcfx-custom-id-' + (customIdCounter++);
}
}
});
});
Give the form a custom class:
mcfx(function(t) {
t.configure("onFormCapture", function(form) {
form.classList.add('rcfx-custom-class');
});
});
Give the form an ID:
mcfx(function(t) {
t.configure("onFormCapture", function(form) {
form.id = 'rcfx-custom-id';
});
});
Ability to use the onFormCapture to perform various code or actions.