从另一个站点上托管的表单收集数据

发布于 2024-12-18 14:28:23 字数 764 浏览 2 评论 0原文

我们有许多客户同意在他们的网站上提交表格后向我们发送他们的表格数据。这可能吗?处理这个问题的最佳方法是什么?我们的网站是用 Coldfusion 构建的,而客户网站各不相同。

我让客户端添加一个脚本标记,以在其表单页面上包含来自我们服务器的 javascript 文件。还让他们向表单按钮添加 onClick 事件,以便在提交表单时调用此 javascript。

这是 javascript 文件:

function cpcshowElements(f) {
var formElements = "";
for (var n=0; n < f.elements.length; n++) {
    box = f.elements[n];
    formElements += box.name + ":" + f.elements[n].value + ",\n";
}
var track = new Image();
/*send data to us*/
track.src="http://XXX.net/form_record.cfm?form="+ formElements + "&self=" + this.location;  
}

提交表单时,调用 cpcshowElements 函数,格式化表单数据,将其附加到 XXX.net/... 的末尾并调用该 url。 form_record.cfm 页面基本上执行一些检查并将数据插入表中。

这个过程确实有效,但并不一致。数据并不总是进入数据库。这就是问题所在。有没有另一种方法可以做到这一点而不会丢失数据?

We have a number of clients that have agreed to send us their form data once a form is submitted on their site. Is this possible and what is the best way to handle this? Our site is built in coldfusion while the client site varies.

I had the client add a script tag to include a javascript file from our server on their form page. Also had them add an onClick event to their form button so this javascript is called on submission of their form.

This is the javascript file:

function cpcshowElements(f) {
var formElements = "";
for (var n=0; n < f.elements.length; n++) {
    box = f.elements[n];
    formElements += box.name + ":" + f.elements[n].value + ",\n";
}
var track = new Image();
/*send data to us*/
track.src="http://XXX.net/form_record.cfm?form="+ formElements + "&self=" + this.location;  
}

On form submission the cpcshowElements function is called, formats the form data, appends it to the end of the XXX.net/...and calls that url. The form_record.cfm page basically does some checks and inserts the data into a table.

This process does work, however not consistently. The data doesn't always make it into the database. That is the problem. Is there another way to do this that won't have data loss?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痞味浪人 2024-12-25 14:28:23

进入数据库的数据是在链条的深处。第一步是找出请求未通过的位置。找到薄弱环节,然后修复该部分。

除了这段 javascript 之外,很可能还有其他问题导致失败。测试流程的每个部分并找出问题所在。很可能,它不在 javascript 中。

The data getting to the database is pretty deep down the chain. The first step is to figure out where the request isn't coming through. Find the weak link, and then fix that part.

Chances are, there are other issues causing the failure than this piece of javascript. Test each part of the process and figure out where the problem lies. Chances are, it isn't in the javascript.

卷耳 2024-12-25 14:28:23

检查服务器上的表单是否通过 onClick 以外的方法提交。如果可以通过按 enter 或按 Tab 键并按 enter 或空格键来提交表单,那么您就错过了一些提交。使用 onSubmit 而不是 onClick 会更加一致。

示例:

<form onsubmit="your_function_here">

另外,如果表单正在提交,然后转到另一个页面,您的 JavaScript 代码可能没有足够的时间来触发。在这种情况下,请在函数中添加延迟,以便在页面消失之前发出对图像的 GET 请求。

Check whether the form on the serve is being submitted by method other than onClick. If the form can be submitted by hitting enter or tabbing and hitting enter or the spacebar, than you are missing some submits. Would work more consistently with onSubmit rather than onClick.

Example:

<form onsubmit="your_function_here">

Also, if the form is submitting and then moving on to another page, you javascript code may not have enough time to fire. In that case, put a delay into your function to allow the GET request for the image to be made before the page evaporates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文