Skip to content

Instantly share code, notes, and snippets.

@garretthyder
Created February 27, 2018 19:58
Show Gist options
  • Save garretthyder/61de702d58a7af4cbf3bc410d22c777b to your computer and use it in GitHub Desktop.
Save garretthyder/61de702d58a7af4cbf3bc410d22c777b to your computer and use it in GitHub Desktop.
No-JS Support for Gravity Forms AJAX
jQuery(document).ready(function($) {
// Gravity Forms no-js support on Ajax
if ( $('.gform_wrapper form[data-target]').length ) {
$('.gform_wrapper form[data-target]').attr('target', $('.gform_wrapper form[data-target]').data('target'));
}
if ( $(".gform_wrapper input[name='nojs_gform_ajax']").length ) {
$(".gform_wrapper input[name='nojs_gform_ajax']").attr('name', 'gform_ajax');
}
});
// Replace Gravity Forms form target attribute as data-target for no-js support
function update_gform_target_nojs( $form_tag, $form ) {
if ( strpos( $form_tag, 'target=' ) !== false ) {
$form_tag = str_replace('target=', 'data-target=', $form_tag);
}
return $form_tag;
}
add_filter( 'gform_form_tag', 'update_gform_target_nojs', 10, 2 );
// Replace Gravity Forms gform_ajax hidden input with nojs_gform_ajax for no-js support
function update_gform_ajaxinput_nojs( $form_string, $form ) {
if ( strpos( $form_string, "name='gform_ajax'" ) !== false ) {
$form_string = str_replace("name='gform_ajax'", "name='nojs_gform_ajax'", $form_string);
}
return $form_string;
}
add_filter( 'gform_get_form_filter', 'update_gform_ajaxinput_nojs', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment