gpsa_load_form_via_ajax

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Load forms with AJAX only if in the context of a Block or Shortcode
  5. Since

Description

Filter to determine if forms should be loaded via AJAX.

Usage

Filter applied globally to all forms

add_filter( 'gpsa_load_form_via_ajax', 'my_custom_function' );

Filter applied to forms on a specific post

add_filter( 'gpsa_load_form_via_ajax_{POST_ID}', 'my_custom_function' );

Parameters

$load_with_ajax bool

Whether to load form via AJAX. Default false.

$form_id int

The Gravity Form ID

$post_id int

The post ID

$args array

The context and data associated with the current context.

context 'document'
post WP_Post|null
context 'block'
block WP_Block|null
block_content string|null
context 'shortcode'
content string
atts array|string

Examples

Load forms with AJAX only if in the context of a Block or Shortcode

This example shows how to conditionally enable AJAX form loading based on the context where the form is being displayed (block, shortcode, or document).

add_filter( 'gpsa_load_form_via_ajax', 'maybe_load_forms_via_ajax', 10, 4 );
function maybe_load_forms_via_ajax( $load_via_ajax, $form_id, $post_id, $args ) {
    switch ( $args['context'] ) {
        case 'block':
        case 'shortcode':
            return true;
        default:
            return false;
    }
}

Since

  • 1.0.0 Hook added.