I use Brevo(SendInBlue) to create forms for my website.
My website is built in WordPress.
Could you please help me find a way through which I could get sent to my email the url adress of the page on which this form has been completed?
The form is the same for every page.
The form is integrated in my website by copying and pasting the iframe code.
Thank you!
I’ve tried to get the link sent to me through
<code>function custom_brevo_form_script() {
document.addEventListener('DOMContentLoaded', function () {
const brevoForm = document.querySelector('iframe[src*="3672f721.sibforms.com"]');
brevoForm.addEventListener('load', function () {
const iframeDocument = brevoForm.contentDocument || brevoForm.contentWindow.document;
const form = iframeDocument.querySelector('form');
form.addEventListener('submit', function (event) {
event.preventDefault();
const currentPageURL = window.location.href;
const formData = new FormData(form);
let formDetails = '';
formData.forEach((value, key) => {
formDetails += `${key}: ${value}n`;
});
fetch("<?php echo admin_url('admin-ajax.php'); ?>", {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: new URLSearchParams({
action: 'send_form_notification',
form_data: formDetails,
page_url: currentPageURL
})
})
.then(response => response.json())
.then(data => {
console.log('Form data and URL successfully sent to WordPress:', data);
form.submit();
})
.catch(error => {
console.error('Error sending form data and URL to WordPress:', error);
form.submit();
});
});
});
});
}
add_action('wp_footer', 'custom_brevo_form_script');
</code>
<code>function custom_brevo_form_script() {
document.addEventListener('DOMContentLoaded', function () {
const brevoForm = document.querySelector('iframe[src*="3672f721.sibforms.com"]');
brevoForm.addEventListener('load', function () {
const iframeDocument = brevoForm.contentDocument || brevoForm.contentWindow.document;
const form = iframeDocument.querySelector('form');
form.addEventListener('submit', function (event) {
event.preventDefault();
const currentPageURL = window.location.href;
const formData = new FormData(form);
let formDetails = '';
formData.forEach((value, key) => {
formDetails += `${key}: ${value}n`;
});
fetch("<?php echo admin_url('admin-ajax.php'); ?>", {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: new URLSearchParams({
action: 'send_form_notification',
form_data: formDetails,
page_url: currentPageURL
})
})
.then(response => response.json())
.then(data => {
console.log('Form data and URL successfully sent to WordPress:', data);
form.submit();
})
.catch(error => {
console.error('Error sending form data and URL to WordPress:', error);
form.submit();
});
});
});
});
}
add_action('wp_footer', 'custom_brevo_form_script');
</code>
function custom_brevo_form_script() {
document.addEventListener('DOMContentLoaded', function () {
const brevoForm = document.querySelector('iframe[src*="3672f721.sibforms.com"]');
brevoForm.addEventListener('load', function () {
const iframeDocument = brevoForm.contentDocument || brevoForm.contentWindow.document;
const form = iframeDocument.querySelector('form');
form.addEventListener('submit', function (event) {
event.preventDefault();
const currentPageURL = window.location.href;
const formData = new FormData(form);
let formDetails = '';
formData.forEach((value, key) => {
formDetails += `${key}: ${value}n`;
});
fetch("<?php echo admin_url('admin-ajax.php'); ?>", {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
body: new URLSearchParams({
action: 'send_form_notification',
form_data: formDetails,
page_url: currentPageURL
})
})
.then(response => response.json())
.then(data => {
console.log('Form data and URL successfully sent to WordPress:', data);
form.submit();
})
.catch(error => {
console.error('Error sending form data and URL to WordPress:', error);
form.submit();
});
});
});
});
}
add_action('wp_footer', 'custom_brevo_form_script');
but I get the error that add_action is not defined.
New contributor
sacramento is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.