[英]Newsletter2Go - Form does not work after filling it with javascript?
I try to automatically fill the newsletter2go form with customer data. 我尝试用客户数据自动填写newsletter2go表单。 The form is getting created dynamically with a javascript code which I got from the newsletter2go backend.
该表单是使用我从newsletter2go后端获取的javascript代码动态创建的。
But I found out, that the form does not work anymore if I fill it by using javascript!? 但是我发现,如果我使用javascript填写表格,该表格将无法使用! It works perfectly fine if I fill it manually by hand.
如果我手动填充它,效果很好。
I executed this code from the developer console: 我从开发者控制台执行了以下代码:
var inputEmail = document.getElementsByClassName("newsletterInput")[0],
inputVorname = document.getElementsByClassName("newsletterInput")[1],
inputNachname = document.getElementsByClassName("newsletterInput")[2],
selectAnrede = document.getElementsByClassName("newsletterSelect")[0];
if (inputEmail.value == "") {
inputEmail.value = 'foo@bar.de';
}
if (selectAnrede.value == "") {
selectAnrede.value = 'm';
}
if (inputVorname.value == "") {
inputVorname.value = 'Edward';
}
if (inputNachname.value == "") {
inputNachname.value = 'Black';
}
The form is getting filled but if I submit then I get to see Sorry, an error has occurred. 表格已填写完毕,但是如果我提交,我会看到抱歉,发生了错误。 Please check your data.
请检查您的数据。
Request Payload at this point: 此时请求有效负载:
Why does it fail? 为什么会失败?
If the browser auto-fills the form, then it works btw. 如果浏览器自动填写表格,那么它将正常工作。
The way the form works is that it only gets updated onchange
. 表单的工作方式是仅在
onchange
时进行更新。 That means if you trigger that manually, your code will work. 这意味着,如果您手动触发该代码,则代码将起作用。
Since this seems a bit like a workaround, a cleaner solution would be to implement it similar to a sample form implementation found on the Newsletter2Go homepage . 由于这似乎是一种解决方法,因此更清洁的解决方案是将其实现为类似于Newsletter2Go主页上的示例表单实现。
The corresponding help article can be found here (only available in German atm). 可以在此处找到相应的帮助文章(仅适用于德语atm)。
BTW, Newsletter2Go offers a recipient profile link that automatically fills the form with customer data. 顺便说一句,Newsletter2Go 提供了一个收件人配置文件链接 ,该链接会自动用客户数据填写表格。 Maybe you can just use that instead.
也许您可以只使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.