![](/img/trans.png)
[英]Display message from Lambda via Javascript after successful form submit
[英]Submit Form should display message after successful submit to Google Sheets
我正在尝试向Google表格提交表单。 此步骤成功完成,我将获得工作表中的所有数字。 现在,我想在提交表单并且Google表格的结果正常后显示成功消息。 我该怎么做?
我已经在javascript和ajax中尝试了各种消息,但是对此没有太多的了解。 我在下面显示了我的代码,因此您可以看一下。
<form name="submit-to-google-sheet">
<select class="form-control custom-form" name="country_code" id="country_code">
<option name="country_code" value="+91">India 91</option>
<option name="country_code" value="+93">Afghanistan 93</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group spec-col col-md-8 col-lg-8 col-sm-12">
<input type="text" class="form-control custom-form" id="phone_no" name="phone_no" placeholder="Enter the Number">
</div>
</div>
<button class="btn btn-submit" id="submit" type="submit">Submit</button>
</div>
</form>
对于将内容提交到Google表格,下面是代码
<script>
const scriptURL = 'GOOGLE SHEETS URL'
const form = document.forms['submit-to-google-sheet']
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => console.log('Success!', response))
.catch(error => console.error('Error!', error.message))
})
</script>
表单成功后,我可以在控制台中看到成功消息。 相反,我想在HTML中显示一个简单的单字行,非常感谢。 一旦Google表格的回复确定并隐藏表单,您的提交便成功了。
编辑:其余代码可从此处引用: https : //github.com/jamiewilson/form-to-google-sheets
按下按钮后,创建空白响应消息
像这样标记
<button class="btn btn-submit" id="submit" type="submit">Submit</button>
<p id="response_message"></p>
现在,在脚本中对fetch函数进行以下更改:
form.addEventListener('submit', e => {
e.preventDefault()
var response_message = document.getElementById("response_message");
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => response_message.innerHTML = "Success!")
.catch(error => response_message.innerHTML = "Error!")
})
如果您使用Google表单将数据提交到Google表格,则表单设置中有一个设置,您可以在其中显示提交时的回复。 无需代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.