Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

525
Vistas
gform not defined after loading gravity form via AJAX

I'm trying to append a gravity form after a certain choice is made. I've a couple choices a visitor can make, and based on that choice I want to load a Gravity form via Ajax.

I've managed to create a successful AJAX call and receive the Gravity form as html. But whenever I try to append this to a div, it tells me gform is not defined. I guess it's trying to load the form.

JS

const dealerForm = jQuery('.js-dealer-form');

jQuery.ajax({
    type: 'GET',
    url: ajax.url,
    data: {
      action: 'load_gravity_form',
      formid: id,
      formtitle: 'true',
      formdescr: 'true',
      formajax: 'true',
    },
  }).done(function(data) {
    dealerForm.html(data);
  });

functions.php

// Get js file from manifest
$manifest = json_decode(file_get_contents(get_template_directory() . '/dist/rev- 
manifest.json'), true);
$jsFile = $manifest['app.bundle.full.js'];

wp_enqueue_script( 'ajax-js', get_template_directory_uri() . '/dist/scripts/' . 
$jsFile, array('jquery') );

wp_localize_script( 'ajax-js', 'ajax', array(
    'url' => admin_url( 'admin-ajax.php' )
));

// Add the action and nopriv action to account for users not logged in
add_action( 'wp_ajax_nopriv_load_gravity_form', 'load_gravity_form' );
add_action( 'wp_ajax_load_gravity_form', 'load_gravity_form' );

function load_gravity_form() {

    // Return the following:
   
    // The form ID
    $gfId = intval($_GET['formid']);

    $gfTitle = filter_var($_GET['formtitle'], FILTER_VALIDATE_BOOLEAN);

    $gfDesc = filter_var($_GET['formdescr'], FILTER_VALIDATE_BOOLEAN);

    $gfAjax = filter_var($_GET['formajax'], FILTER_VALIDATE_BOOLEAN);

    // This is the shortcode to embed the form
    gravity_form($gfId, $gfTitle, $gfDesc, false, '', $gfAjax, 1);

    die();

}

header.php

$forms = GFAPI::get_forms();

foreach ($forms as $form) {
     gravity_form_enqueue_scripts( $form['id'], true );
}

$GLOBALS['timberContext'] = \Timber\Timber::get_context();
ob_start();

When I place {{ function('do_shortcode', '[gravityform id="25" title="false" description="true" ajax="true"]') }} in my template, gform is not longer not defined. But that should not be the right solution I guess.

Any ideas?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda