Skip to content

Instantly share code, notes, and snippets.

@adczk
Last active July 27, 2022 15:12
Show Gist options
  • Select an option

  • Save adczk/e33789bf9c19c574cc391b18dfc7277f to your computer and use it in GitHub Desktop.

Select an option

Save adczk/e33789bf9c19c574cc391b18dfc7277f to your computer and use it in GitHub Desktop.
Forminator - automatically move to next page on radio button selection on paged forms
<?php
/*
Use as MU plugin
Put this string in "Additional CSS Classes" field
in "Styling" tab of settings
of the "radio" field that should cause "auto next page":
next-on-click
-------
Tested with Forminator 1.17.2
*/
add_action( 'wp_footer', 'wpmu_forminator_radio_next', 99 );
function wpmu_forminator_radio_next() {
?>
<script>
jQuery(document).ready(function($) {
$(document).on('after.load.forminator', function(e, form_id) {
var next_button = document.querySelector('.forminator-button-next'),
click_event = new CustomEvent('change_evt'),
clickable_elements = document.querySelectorAll('.next-on-click .forminator-radio'),
radios = document.querySelectorAll('.next-on-click input[type="radio"]');
clickable_elements.forEach(
clickable_element => {
clickable_element.addEventListener('click', wpmudev_clickables_event_callback)
}
)
function wpmudev_clickables_event_callback() {
radios.forEach(radio => {
radio.addEventListener('change', wpmudev_change_evt_callback)
})
}
function wpmudev_change_evt_callback(e) {
if (e.currentTarget.checked) {
$('.forminator-button-next').trigger('click');
}
}
});
setTimeout(function() {
$('.forminator-custom-form').trigger('after.load.forminator');
}, 100);
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment