Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

535
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda