I have a multi-page form.
I would like to execute some custom JavaScript on the last page of this form. Theoretically, all I need to do is get the current page number and write a conditional expression.
Simple, right? Apparently not.
My initial decision was this:
if ($('gform_page').last().css('display') !== 'none') {
}
but $('...').css('display')returns undefinedfor every element I tried on the form. User scripts were run every time the user clicked the "Next" button. No cigars.
Then, looking at the documentation for Gravity Forms documents , I found two useful types of events: gform_post_renderand gform_page_loaded.
However, the documentation does not provide instructions on how to access the parameters.
jQuery(document).bind('gform_page_loaded', function(event, form_id, current_page){
console.log(current_page);
});
, , , functions.php header.php( ):
<?php
function enqueue_custom_script($form, $is_ajax){
if ($is_ajax) :
echo '<script>console.log(current_page);</script>';
endif;
}
add_action("gform_enqueue_scripts", "enqueue_custom_script", 10, 2);
?>
:
, , ?