Have you ever filled out a form, clicked “submit,” and then had to scroll back up the page to see if your submission was successful? This common issue can lead to a less-than-ideal user experience, as success or error messages can be easily missed.
Fortunately, there’s a simple, elegant solution. By using a custom HTML snippet, you can replace the standard inline messages with a modern, eye-catching popup. This ensures users are immediately notified of their form’s status without having to search for a hidden message.
In this guide, we’ll walk you through a simple and powerful solution to create a beautiful, custom popup for your JetFormBuilder success and error messages.
The solution is comprised of two main parts: a CSS section for styling the popup and overlay, and a JavaScript section for controlling its behavior.
The CSS code styles the two main elements: the semi-transparent overlay that blurs the background (#overlay) and the popup message box itself (#messagePopup). This code ensures the popup is centered on the page, looks great on all devices, and has a professional feel.
The HTML is straightforward, containing two div elements for the overlay and the popup. The div with the ID #popupMessageContent is where your form’s success or error message will be dynamically displayed.
This is where the magic happens. The JavaScript snippet, powered by jQuery, performs the following key functions:
closePopup() function, attached to a button, that allows users to easily dismiss the message.
Ready to improve your form’s user experience? Follow these simple steps to add this custom popup to your website.
First, copy the entire block of code provided below. You will need a snippet plugin or a theme’s custom code editor (like Elementor’s Custom Code feature) to add this to your site.
Inside the <script> tag, you will find an array named targetPages.
var targetPages = ['contact1', 'contact2'];
You must update this array to include the slugs of the pages where your JetFormBuilder forms are located. Replace 'contact1' and 'contact2' with the slugs of your actual contact or submission pages. For example, if your contact page URL is yoursite.com/get-in-touch/, the slug is 'get-in-touch'. You can add as many slugs as you need.
After you have updated the targetPages array, save your snippet. Clear any caching on your site and then visit one of your target pages. Submit your JetFormBuilder form, and you should now see a custom message popup instead of the standard inline text.
/* Overlay Styling */
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.4);
z-index: 100;
backdrop-filter: blur(5px) brightness(40%);
display: none;
}
/* Popup Styling */
#messagePopup {
position: fixed;
left: 50%;
transform: translateX(-50%);
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
z-index: 101;
box-sizing: border-box;
text-align: center;
display: none;
opacity: 0;
top: 45%;
}
#popupMessageContent {
margin-bottom: 20px;
}
#messagePopup button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
#messagePopup button:hover {
background-color: #0056b3;
}
@media (max-width: 1024px) {
#messagePopup {
width: 80%;
}
}
@media (max-width: 767px) {
#messagePopup {
width: 90%;
}
}
jQuery(document).ready(function($) {
// Define an array of pages where the script should run
var targetPages = ['contact1', 'contact2'];
// Get the current page slug
var currentSlug = window.location.pathname.split('/').filter(Boolean).pop();
// Check if the current page's slug is in the targetPages array
if (targetPages.includes(currentSlug)) {
function openPopupWithMessage(messageText) {
$('#popupMessageContent').text(messageText);
$('#overlay').fadeIn(300);
$('#messagePopup').css('top', '45%').show().animate({opacity: 1, top: "50%"}, 300);
}
window.closePopup = function() {
$('#messagePopup').animate({opacity: 0, top: "45%"}, 300, function() {
$(this).hide();
});
$('#overlay').fadeOut(300);
};
// Function to check and display form messages, triggered by form submission
function checkAndDisplayFormMessages() {
let successMessage = $('.jet-form-builder-message--success').text();
let errorMessage = $('.jet-form-builder-message--error').text();
if (successMessage || errorMessage) {
let message = successMessage || errorMessage;
openPopupWithMessage(message);
$('.jet-form-builder-message--success, .jet-form-builder-message--error').hide();
}
}
// Attach an event listener to form submission to ensure the popup only shows after submission
$('form').on('submit', function(event) {
$(document).ajaxComplete(function() {
checkAndDisplayFormMessages(); // Check again after any AJAX call completes
});
});
}
});
Powered by Webspires © Boost My Croco 2025. All Rights Reserved.