• Resolved kujain

    (@kujain)


    Though the title above is true, I am not completely certain the form issue is due to being used in a twig template (timber).

    I have added a content variable and then inserted into the twig template for rendering.

    timber.php:
    $context['contact_form_html'] = do_shortcode($content_post[0]->custom['contact_form']);

    footer.twig:
    {{ contact_form_html}}

    The form renders fine BUT there’s no submission or even capture. The page reloads (ie. no ajax) and nothing gets tracked, not is js triggered anywhere. No submissions are saved in the db as well. I think the plugin’s js files are not getting loaded here but not sure.

    Please do advise!
    Thanks!

    • This topic was modified 6 years, 10 months ago by kujain.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Kujain,

    I think you’re right – it does sound like an issue with the JavaScript file not being loaded. Probably because the plugin relies on a “lazy loading” method which is rather simplistic.

    Can you try adding the following code to enqueue the script manually to see if that solves your issue?

    
    add_action( 'wp_enqueue_scripts', function() {
       wp_enqueue_script('html-forms');
    }, 90 );
    

    Thanks in advance!

    Thread Starter kujain

    (@kujain)

    THanks for your reply Danny!

    Actually I managed to resplve this last night!
    I think you are correct about the lazy loading aspect which is why the assets do not get loaded when I add the shortcodes within the template php file.
    However, if I resolve the shortcode within the twig file instead, the supporting assets do get loaded. ie. instead of the above in the template.php and the twig file, I did this:

    timber.php:
    $context['contact_form_html'] = $content_post[0]->custom['contact_form'];

    footer.twig:
    {{ contact_form_html|shortcodes}}

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Issue with HTML Form when inserting into a Twig template’ is closed to new replies.