I had tried different variations of this trouble solution, but in result just text inputs sent to email, but elements with “wpforms-selected” class don’t send, when nextformspage.js scripts active on website and everything goes wrong. This scripts active on website https://staging-new.deutsche-thermo.de/mobile-heizung-lp-2/ , which have developed on wordpress. In this case I can edit just forms.js, nextformspage.js and functions.php files. So how can I fix this codes and error in website?
Here is last version of forms.js file in website
const wpForm = document.querySelector('.lindenfield-step-form-v1');
const choiceItems = document.querySelectorAll('.lindenfield-step-form-v1 .wpforms-image-choices-item');
const wpformsPage = document.querySelectorAll('.lindenfield-step-form-v1 .wpforms-page');
const wpformsLastPage = document.querySelectorAll('.lindenfield-step-form-v1 .wpforms-page.last.wpform-footer-btns');
const wpformButtonNext = document.querySelectorAll('.lindenfield-step-form-v1 .wpforms-page-next');
const wpformButtonBack = document.querySelectorAll('.lindenfield-step-form-v1 .wpforms-page-prev');
const wpformsButtonSubmit = document.querySelector('.lindenfield-step-form-v1 .wpforms-submit');
const wpformsFields = document.querySelectorAll('.lindenfield-step-form-v1 .wpforms-field');
const wpformsTextFields = document.querySelectorAll('.lindenfield-step-form-v1 .wpforms-field.wpforms-field-text');
const wpformsRequiredField = document.querySelectorAll('.lindenfield-step-form-v1 .wpforms-field-required');
const wpformsIndicatorWrap = document.querySelector('.lindenfield-step-form-v1 .wpforms-page-indicator-page-progress-wrap');
const wpformsIndicatorProgress = document.querySelector('.lindenfield-step-form-v1 .wpforms-page-indicator-page-progress');
const wpformsIndicatorContainer = document.createElement('div');
wpformsIndicatorContainer.className = 'wpforms-page-indicator-container';
wpformsIndicatorProgress.appendChild(wpformsIndicatorContainer);
const wpformsIndicatorText = document.createElement('div');
wpformsIndicatorText.className = 'wpforms-page-indicator-text';
wpformsIndicatorContainer.appendChild(wpformsIndicatorText);
const wpformsIndicatorProgressWidth = Math.round(parseFloat(wpformsIndicatorProgress.style.width));
wpformsIndicatorText.innerText = wpformsIndicatorProgressWidth + '% geschaft';
//current page index
let currentPageIndex = 0;
for (var item = 0; item < choiceItems.length; item++) {
const choiceItemOnHover = document.createElement('div');
choiceItemOnHover.className = "wpforms-choices-header-onhover";
const label = choiceItems[item].querySelector('.lindenfield-step-form-v1 .wpforms-image-choices-label');
choiceItemOnHover.innerText = label ? label.innerText : '';
choiceItems[item].append(choiceItemOnHover);
}
showButton();
function showButton() {
wpformButtonNext.forEach((button, index) => {
const page = wpformsPage[index];
if (page.getAttribute('data-page')) {
const selectedItems = page.querySelectorAll(`.lindenfield-step-form-v1 .wpforms-image-choices-item.wpforms-selected`);
if (selectedItems.length === 0) {
button.style.visibility = 'hidden';
} else {
button.style.visibility = 'visible';
}
} else {
button.style.visibility = 'hidden';
}
});
}
function progressNext() {
const totalPages = wpformsPage.length;
currentPageIndex = Array.from(wpformsPage).indexOf(this.closest('.lindenfield-step-form-v1 .wpforms-page'));
if (currentPageIndex === totalPages - 2 || currentPageIndex === totalPages - 1) {
const actualPercentValue = '95%';
wpformsIndicatorProgress.style.width = actualPercentValue;
wpformsIndicatorText.innerText = wpformsIndicatorProgress.style.width + ' - Fastgeschafft';
wpformsIndicatorText.setAttribute('data-progress-width', wpformsIndicatorProgressWidth);
/* const screenWidth = window.innerWidth;
if (screenWidth <= 768) {
wpformsIndicatorText.style.right = '-20px';
} else {
wpformsIndicatorText.style.right = '-40px';
} */
wpForm.style.backgroundColor = 'white';
} else {
const pixelProgressWidth = window.getComputedStyle(wpformsIndicatorProgress).getPropertyValue('width');
const currentIndicatorWidth = window.getComputedStyle(wpformsIndicatorWrap).getPropertyValue('width');
const percentageValue = Math.round((parseFloat(pixelProgressWidth) / parseFloat(currentIndicatorWidth)) * 100);
const actualPercentValue = wpformsIndicatorProgressWidth + percentageValue;
wpformsIndicatorText.innerText = actualPercentValue + '% geschafft';
wpformsIndicatorText.setAttribute('data-progress-width', wpformsIndicatorProgressWidth);
}
showButton();
buttonDetect();
}
function progressBack() {
const pixelProgressWidth = window.getComputedStyle(wpformsIndicatorProgress).getPropertyValue('width');
const currentIndicatorWidth = window.getComputedStyle(wpformsIndicatorWrap).getPropertyValue('width');
const percentageValue = Math.round((parseFloat(pixelProgressWidth) / parseFloat(currentIndicatorWidth)) * 100);
const actualPercentValue = wpformsIndicatorProgressWidth - percentageValue;
wpformsIndicatorText.innerText = -actualPercentValue + '% geschafft';
showButton();
}
function addSelected(event) {
const clickedChoiceItem = event.currentTarget;
const currentPage = clickedChoiceItem.closest('.wpforms-page');
const choiceItemsOnPage = currentPage.querySelectorAll('.wpforms-image-choices-item');
choiceItemsOnPage.forEach(item => item.classList.remove('wpforms-selected'));
clickedChoiceItem.classList.add('wpforms-selected');
progressNext.call(clickedChoiceItem);
}
if (choiceItems) {
for (var i = 0; i < wpformButtonNext.length; i++) {
wpformButtonNext[i].addEventListener('click', progressNext);
}
for (var i = 0; i < wpformButtonBack.length; i++) {
wpformButtonBack[i].addEventListener('click', progressBack);
}
for (var i = 0; i < choiceItems.length; i++) {
choiceItems[i].addEventListener('click', addSelected);
}
} else {
console.error('wpformButtonNext not found');
}
wpformsButtonSubmit.innerText = 'Angebote erhalten';
function checkFields(page) {
const textFields = page.querySelectorAll('.wpforms-field.wpforms-field-text input');
const requiredFields = page.querySelectorAll('.wpforms-field-required input');
let anyFieldEmpty = false;
textFields.forEach((field) => {
if (field.value.trim() === '') {
anyFieldEmpty = true;
}
});
requiredFields.forEach((field) => {
if (field.value.trim() === '') {
anyFieldEmpty = true;
}
});
if (anyFieldEmpty === true) {
wpformsButtonSubmit.disabled = true;
} else {
wpformsButtonSubmit.disabled = false;
}
}
function buttonDetect() {
if (wpformsButtonSubmit) {
if (currentPageIndex < wpformsPage.length - 1) {
const nextPage = wpformsPage[currentPageIndex + 1];
nextPage.addEventListener('input', () => checkFields(nextPage));
checkFields(nextPage);
} else {
console.log('No next page found');
}
}
}
document.addEventListener("DOMContentLoaded", function () {
const screenWidth = window.innerWidth;
if (screenWidth <= 768) {
if (wpformsIndicatorProgressWidth <= 20) {
wpformsIndicatorText.style.right = '-100px';
wpformsIndicatorText.innerText = wpformsIndicatorProgressWidth + '% geschafft';
} else if (wpformsIndicatorProgressWidth >= 20) {
console.log("s17");
wpformsIndicatorText.style.right = '-75px';
} else if (wpformsIndicatorProgressWidth >= 80) {
wpformsIndicatorText.style.right = '-20px';
}
}
const firmaInput = document.querySelector('.wpforms-input-firma');
const nameInput = document.querySelector('.wpforms-input-name');
const plzInput = document.querySelector('.wpforms-input-plz');
const phoneInput = document.querySelector('.wpforms-input-telefon');
const errorText = document.querySelector('.wpforms-error');
// Till here everything is okay
function validateFirmaInput() {
const maxLength = 39;
const trimmedValue = trimInputValue(firmaInput);
if (trimmedValue.length > maxLength) {
firmaInput.value = trimmedValue.slice(0, maxLength);
} else {
const sanitizedValue = trimmedValue.replace(/[^A-Za-z()s]/g, '');
firmaInput.value = sanitizedValue;
}
}
function validateNameInput() {
const maxLength = 39;
const trimmedValue = trimInputValue(nameInput);
if (trimmedValue.length > maxLength) {
nameInput.value = trimmedValue.slice(0, maxLength);
}
const sanitizedValue = trimmedValue.replace(/[^A-Za-z()s]/g, '');
nameInput.value = sanitizedValue;
}
function validatePlzInput() {
const value = trimInputValue(plzInput);
const sanitizedValue = value.replace(/[^0-9]/g, '');
if (sanitizedValue.length > 5) {
plzInput.value = sanitizedValue.slice(0, 5);
} else {
plzInput.value = sanitizedValue;
}
}
function validatePhoneInput() {
const value = trimInputValue(phoneInput);
const maxLength = 17;
if (value.length > maxLength) {
phoneInput.value = value.slice(0, maxLength);
}
}
firmaInput.addEventListener('input', validateFirmaInput);
nameInput.addEventListener('input', validateNameInput);
plzInput.addEventListener('input', validatePlzInput);
phoneInput.addEventListener('input', validatePhoneInput);
nameInput.addEventListener('keypress', function (e) {
const charCode = (e.which) ? e.which : event.keyCode;
const allowedChars = /[A-Za-z()s]/;
const char = String.fromCharCode(charCode);
if (!char.match(allowedChars)) {
e.preventDefault();
}
});
plzInput.addEventListener('keypress', function (e) {
const charCode = (e.which) ? e.which : event.keyCode;
const allowedChars = /[0-9]/;
const char = String.fromCharCode(charCode);
if (!char.match(allowedChars)) {
e.preventDefault();
}
});
phoneInput.addEventListener('keypress', function (e) {
const charCode = (e.which) ? e.which : event.keyCode;
const allowedChars = /[0-9,*+()-_s]/;
const char = String.fromCharCode(charCode);
if (!char.match(allowedChars)) {
e.preventDefault();
}
});
function trimInputValue(input) {
if (input && input.value) {
return input.value.replace(/^s+|s+$/g, '');
}
return '';
}
function checkFields(page) {
const textFields = page.querySelectorAll('.wpforms-field.wpforms-field-text input');
const requiredFields = page.querySelectorAll('.wpforms-field-required input');
let anyFieldEmpty = false;
textFields.forEach((field) => {
if (field.value.trim() === '') {
anyFieldEmpty = true;
}
});
requiredFields.forEach((field) => {
if (field.value.trim() === '') {
anyFieldEmpty = true;
}
});
const isValidName = validateNameInput();
const isValidFirma = validateFirmaInput();
const isValidPlz = validatePlzInput();
const isValidPhone = validatePhoneInput();
if (anyFieldEmpty === true || !isValidName || !isValidFirma || !isValidPlz || !isValidPhone) {
wpformsButtonSubmit.disabled = true;
} else {
wpformsButtonSubmit.disabled = false;
}
}
wpformsPage.forEach(function (page) {
page.addEventListener('input', () => checkFields(page));
});
// Initialize field validation on page load
checkFields(wpformsPage[0]);
});
And here is nextformspage.js file, where had wrotten scripts for transition
var isClickAllowed = true;
function addTransitionClass() {
wpformsPage.forEach(function (page) {
page.classList.add("anim-trans");
});
wpformsIndicatorProgress.classList.add("anim-bar");
setTimeout(function () {
wpformsPage.forEach(function (page) {
page.classList.remove("anim-trans");
});
wpformsIndicatorProgress.classList.remove("anim-bar");
}, 1000);
}
choiceItems.forEach(function (item) {
item.addEventListener("click", function (event) {
event.preventDefault();
if (isClickAllowed) {
isClickAllowed = false;
var closestPage = item.closest('.wpforms-page');
var nextPageButton = closestPage.querySelector('.wpforms-page-next');
nextPageButton.click();
addTransitionClass();
setTimeout(function () {
isClickAllowed = true;
}, 100);
}
});
});
function handleButtonClick(button) {
button.addEventListener("click", function () {
if (isClickAllowed) {
isClickAllowed = false;
addTransitionClass();
setTimeout(function () {
isClickAllowed = true;
}, 100);
}
});
}
choiceItems.forEach(function (item) {
handleButtonClick(item);
});
wpformButtonNext.forEach(function (item) {
handleButtonClick(item);
});
wpformButtonBack.forEach(function (item) {
handleButtonClick(item);
});
<?php
/**
* GeneratePress.
*
* @package GeneratePress
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
require_once('session.php');
require_once('tracking.php');
require_once('lead.php');
require_once('regional.php');
require_once('wpsl.php');
require_once('regional_sitemap.php');
/*
* Add Actions
*/
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
add_action('wp_print_scripts', 'fg1_dequeue_scripts', 100);
add_action('wp_print_styles', 'fg1_dequeue_styles', 100);
add_action('wp_head', 'fg1_ajax_url_nonce');
add_action('wp_enqueue_scripts', 'custom_enqueue_styles_and_scripts');
add_action('wp_enqueue_scripts', 'forms_scripts');
add_action('enqueue_block_editor_assets', function () {
wp_enqueue_style('local-fonts', "/wp-content/themes/generatepress-child/style.css", false, '1.0', 'all');
});
//login cookie secure
add_action('init', 'lf_wp_login_cookie_secure', 10);
function lf_wp_login_cookie_secure()
{
if (strpos($_SERVER['REQUEST_URI'], 'wp-login.php') !== false) {
if (!isset($_COOKIE['lm_wp_login_secure']) or $_COOKIE['lm_wp_login_secure'] != "TSvrEQHnzVaoriNmM5Sb") {
header("HTTP/1.0 403 Forbidden");
exit();
}
}
}
function custom_enqueue_styles_and_scripts()
{
wp_enqueue_script('custom-js', '/wp-content/themes/generatepress-child/style.js', array('jquery'), '1.0.0', true);
}
function forms_scripts()
{
wp_enqueue_script('nextformpage-js', '/wp-content/themes/generatepress-child/nextformpage.js', array('jquery'), '1.0.0', true);
wp_enqueue_script('forms-js', '/wp-content/themes/generatepress-child/forms.js', array('jquery'), '1.0.0', true);
}
/**
* Modify the required field indicator
*
* @link https://wpforms.com/developers/how-to-change-required-field-indicator/
*/
function wpf_dev_required_indicator( $text ) {
return ' <span class="wpforms-required-label">' . __( ' ', 'wpforms' ) . '</span>';
}
add_filter( 'wpforms_get_field_required_label', 'wpf_dev_required_indicator', 10, 1 );
//End Modify
function fg1_dequeue_scripts()
{
$wp_scripts = wp_scripts();
if (isset($wp_scripts->registered['lazyload-youtube-js'])) {
$wp_scripts->registered['lazyload-youtube-js']->src = '/wp-content/themes/generatepress-child/lazyload-youtube.js';
}
}
function fg1_dequeue_styles()
{
//wp_dequeue_style( 'aawp-styles' );
}
function fg1_ajax_url_nonce()
{
?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url("admin-ajax.php"); ?>';
var ajaxnonce = '<?php echo wp_create_nonce("itr_ajax_nonce"); ?>';
</script>
<?php
}
/**
* Removes empty paragraph tags from shortcodes in WordPress.
*/
function tg_remove_empty_paragraph_tags_from_shortcodes_wordpress($content)
{
$toFix = array(
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
return strtr($content, $toFix);
}
add_filter('the_content', 'tg_remove_empty_paragraph_tags_from_shortcodes_wordpress');
function set_cache_value($cache_key, $cache_value)
{
global $wpdb;
$cache_value_db = $wpdb->get_row($wpdb->prepare("SELECT cache_value FROM fg1_cache WHERE cache_key = %s LIMIT 1;", array($cache_key)));
if (!empty($cache_value_db)) {
$wpdb->query($wpdb->prepare("UPDATE fg1_cache SET cache_value = '" . $cache_value . "' WHERE cache_key = %s LIMIT 1;", array($cache_key)));
} else {
$wpdb->insert('fg1_cache', array("cache_key" => $cache_key, "cache_value" => $cache_value));
}
}
function get_cache_value($cache_key)
{
global $wpdb;
$ret = false;
$cache_value = $wpdb->get_row($wpdb->prepare("SELECT cache_value FROM fg1_cache WHERE cache_key = %s LIMIT 1;", array($cache_key)));
if (!empty($cache_value))
$ret = $cache_value->cache_value;
return $ret;
}
add_action('init', 'custom_lazyload_youtube_proxy', 10, 0);
function custom_lazyload_youtube_proxy()
{
global $wp;
if (strpos($_SERVER['REQUEST_URI'], '/ythumb/') !== false) {
$src = $_GET['src'];
if (substr($src, 0, 23) == 'https://i2.ytimg.com/vi') {
header('Content-Type: image/jpeg');
readfile($src);
}
exit();
}
}
add_action('rest_api_init', 'custom_rest_api_init');
function custom_rest_api_init()
{
register_rest_route(
'lc/v1',
'/get_all_wpforms/',
array(
'methods' => 'GET',
'callback' => 'get_all_wpforms'
)
);
}
function get_all_wpforms()
{
$args = array(
'numberposts' => -1,
'post_type' => 'wpforms'
);
$wpforms_posts = get_posts($args);
return $wpforms_posts;
}
function display_year()
{
$year = date('Y');
return $year;
}
add_shortcode('year', 'display_year');
add_shortcode('month', 'display_month');
function display_month()
{
$monatsnamen = array(
1 => "Januar",
2 => "Februar",
3 => "März",
4 => "April",
5 => "Mai",
6 => "Juni",
7 => "Juli",
8 => "August",
9 => "September",
10 => "Oktober",
11 => "November",
12 => "Dezember"
);
$monat = date('n');
return $monatsnamen[$monat];
}
function add_search_box($items, $args)
{
$items .= '<li>' . get_search_form(false) . '</li>';
return $items;
}
add_filter('wp_nav_menu_topmenue_items', 'add_search_box', 10, 2);
add_filter('generate_search_placeholder', 'test_suche');
function test_suche()
{
return 'Wonach suchen Sie?';
}
add_filter('pre_get_posts', 'SearchFilter');
function SearchFilter($query)
{
if ($query->is_search) {
$query->set('post__not_in', array(2, 129, 288, 425, 432, 594, 710, 885, 892, 1027, 1068, 1078, 1081, 1237, 1230, 1308, 1310, 1362, 1364, 1433, 2498, 3412, 3415, 3417, 3420, 3422, 3424, 4037, 7234, 7236, 7272, 7283, 7298, 7240, 7505, 7695, 8480, 8939, 9562, 10632, 10691, 10702, 10713, 10730, 10763, 10771, 10799, 10805, 10817, 10821, 10824, 10830, 10834, 10857, 11316, 11424, 11432, 11434, 12331));
}
return $query;
}
function limit_author_posts_per_page($query)
{
if ($query->is_author()) {
$query->set('posts_per_page', 6);
}
return $query;
}
add_filter('pre_get_posts', 'limit_author_posts_per_page');
//WPforms Spam Schutz Token Gültigkeit erhöhen, sodass das Formular länger gecached und mit Spam-Schutz funktioniert
add_filter('wpforms_form_token_check_before_today', 'lf_wpforms_form_token_check_before_today');
function lf_wpforms_form_token_check_before_today($valid_token_times_before)
{
$valid_token_times_before = [];
$valid_days_ago = 100;
for ($i = 1; $i <= $valid_days_ago; $i++) {
$valid_token_times_before[] = ($i * 86400);
}
return $valid_token_times_before;
}
function last_modified_shortcode()
{
$date_format = 'd.m.Y';
$last_modified = get_the_modified_date($date_format);
return $last_modified;
}
add_shortcode('last_modified', 'last_modified_shortcode');
I want solve this problem, and in result recieve data from all elements with ‘wpforms-selected’ class in email