<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Ajax Contact Form for Wordpress, Joomla, Drupal - Material Design</title>
    <meta name="description" content="Material Ajax Form Generator - how to create an Ajax Contact Form with Php Form Builder for Wordpress, Joomla, Drupal or any CMS">
    <link rel="canonical" href="https://www.phpformbuilder.pro/templates/material-forms/ajax-loaded-contact-form-1.html" />

    <!-- Materialize CSS -->

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

    <!-- Material icons CSS -->

    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    <!-- demo styles -->

    <link rel="stylesheet" href="../assets/stylesheets/code-preview-styles.min.css">
</head>

<body>

    <h1 class="center-align">Php Form Builder - Ajax Contact Form for Wordpress, Joomla, Drupal or any CMS<br><small>Material Design version</small></h1>

    <div class="container">

        <div class="row">

            <div class="col m11 l10">
                <p>The Ajax form source code is not available on this page, you'll find it in the <em>templates/ajax-forms</em> folder</p>
                <div class="center-align">
                    <a href="https://www.phpformbuilder.pro/documentation/class-doc.php#ajax-loading" class="btn grey darken-1 waves-effect waves-light btn-small"><strong>Ajax loading</strong> - documentation here <i class="material-icons right">arrow_right</i></a>
                    <p>&nbsp;</p>
                </div>
                <div id="ajax-form"></div>
            </div>
        </div>
    </div>

    <!-- jQuery -->

    <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

    <!-- Materialize JavaScript -->

    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>

    <!-- Ajax form loader -->

    <script src="../../phpformbuilder/plugins/ajax-data-loader/ajax-data-loader.min.js"></script>

    <script>
        // --- SETUP YOUR FORM(S) BELOW IN THE "ajaxForms" VARIABLE ---
        var ajaxForms = [
            {
                formId: 'ajax-contact-form-1',
                container: '#ajax-form',
                url: 'ajax-forms/contact-form-1.php'
            }
        ];

        // --- NO NEED TO CHANGE ANYTHING AFTER THIS LINE ---
        // --- COPY/PASTE THE FOLLOWING CODE IN THE HTML FILE THAT WILL LOAD THE FORM ---

        document.addEventListener('DOMContentLoaded', function() {
            ajaxForms.forEach(function(currentForm) {
                const $formContainer = document.querySelector(currentForm.container);
                if (typeof($formContainer.dataset.ajaxForm) === 'undefined') {
                    fetch(currentForm.url)
                    .then((response) => {
                        return response.text()
                    })
                    .then((data) => {
                        $formContainer.innerHTML = '';
                        $formContainer.dataset.ajaxForm = currentForm;
                        $formContainer.dataset.ajaxFormId = currentForm.formId;
                        loadData(data, currentForm.container);
                    }).catch((error) => {
                        console.log(error);
                    });
                }
            });
        });
    </script>
</body>

</html>
