如何将HTML表单数据发送到Google表格?

3

我正在尝试将HTML表单数据发送到Google表格。我已经按照一些教程的步骤进行了操作,但是无法将表单数据发送到Google表格。我已经成功部署了Google脚本并复制了链接,然后将其与HTML链接起来,但没有结果。我在这里究竟缺少什么呢?

恳请您的指导。

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Form</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

</head>

<body>
    <nav class="navbar navbar-light bg-light">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">
                <img src="https://www.freeiconspng.com/uploads/tumblr-logo-icon-9.png" alt="" width="30" height="24" class="d-inline-block align-text-top"> Test Form
            </a>
        </div>
    </nav>

    <div class="container">

        <form class="row g-3" method="POST" autocomplete="off" name="test_form">

            <select class="form-select form-select-lg mb-3" name="title" aria-label=".form-select-lg example">
                <option selected>Open this select menu</option>
                <option value="1">Mr.</option>
                <option value="2">Miss</option>
                <option value="3">Mrs.</option>
            </select>

            <div class="container">
                <div class="row g-2">
                    <div class="col-6">
                        <div class="col">
                            <input type="text" class="form-control" name="firstname" placeholder="First name" aria-label="First name">
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="col">
                            <input type="text" class="form-control" name="lastname" placeholder="Last name" aria-label="Last name">
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="col">
                            <input type="email" class="form-control" name="email" placeholder="Email" aria-label="Email">
                        </div>
                    </div>
                    <div class="col-6">
                        <div class="col">
                            <input type="text" class="form-control" name="telephone" placeholder="Telephone" aria-label="Telephone">
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-floating">
                <textarea class="form-control" name="comment" placeholder="Leave a comment here" id="floatingTextarea2" style="height: 100px"></textarea>
                <label for="floatingTextarea2">Comments</label>
            </div>

            <div class="col-12">
                <button class="btn btn-primary" type="submit" name="submit" value="send message">Submit form</button>
            </div>
        </form>

        <script type="text/javascript">
            const scriptURL = 'https://script.google.com/macros/s/AKfycbyWrl6cQr8C6PatE2tTZ3kJWi0lInw4rgu4nRBB8AqY3X7GDJ_6387yOtqsBJSjdV96og/exec'
            const form = document.forms['google-sheet']

            form.addEventListener('submit', e => {
                e.preventDefault()
                fetch(scriptURL, {
                        method: 'POST',
                        body: new FormData(form)
                    })
                    .then(response => alert("Thanks for Contacting us..! We Will Contact You Soon..."))
                    .catch(error => console.error('Error!', error.message))
            })
        </script>
        <!-- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script> -->
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
 
    </div>
</body>

</html>

1
本教程将帮助您 https://dev.to/omerlahav/submit-a-form-to-a-google-spreadsheet-1bia - navnath
@NavnathJadhav 刚刚尝试了,没有结果。 - Raisul Islam
配置丢失了吗? - navnath
@NavnathJadhav,打字错误。你提到的教程很好地起作用了。 - Raisul Islam
1个回答

1
你可以从这里开始学习教程。
请确保仔细添加“添加新项目触发器”、“将项目发布为 Web 应用程序”和“输入你的 Web 应用程序 URL”。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接