如何使用 URL 预填充 wufoo 字段?

How to prepopulate a wufoo field with an URL?

Wufoo 似乎有一个错误,因为我无法使用 url 预填充我的嵌入式 Wufoo 表单的字段。我正在使用 javascript 嵌入方法,您可以使用 'defautValues' 选项对其进行初始化。

不幸的是,如果我用 url 初始化一个字段(例如:'defaultValues':'Field1=https://youtube.com'),Wufoo 会从 url 中删除 1 个斜杠,这使其无效。

我尝试了 "urlencoding" url(例如:'defaultValues':'Field1=https%3A%2F%2Fyoutube.com')但是 wufoo 产生了一个错误并且没有显示表格。

这是一个示例表单,您可以自己尝试查看行为:

<div id="wufoo-mrmifr316ya92y">
Fill out my <a href="https://democratech.wufoo.com/forms/mrmifr316ya92y">online form</a>.
</div>
<script type="text/javascript">var mrmifr316ya92y;(function(d, t) {
var s = d.createElement(t), options = {
'userName':'democratech',
'formHash':'mrmifr316ya92y',
'autoResize':true,
'height':'259',
'async':true,
'host':'wufoo.com',
'defaultValues':'Field1=https://youtube.com', //removes 1 slash (https:/youtube.com)
//'defaultValues':'Field1=https%3A%2F%2Fyoutube.com', //produces an error
'header':'hide',
'ssl':true};
s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'www.wufoo.com/scripts/embed/form.js';
s.onload = s.onreadystatechange = function() {
var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return;
try { mrmifr316ya92y = new WufooForm();mrmifr316ya92y.initialize(options);mrmifr316ya92y.display(); } catch (e) {}};
var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);
})(document, 'script');</script>

你确认错误了吗?除了从字段中删除 https:// 之外,还有其他解决方法吗(这对我来说不是一个很好的解决方法)?

这个问题已经在这里问过:Why cant I add a URL as a prefilled Wufoo field entry?但由于没有得到回答,我想我会问一个更详细的问题,并提供一个实际尝试代码的例子。

这并不是真正的答案,而是一种在某些情况下可行的解决方法。如果您正在使用 wufoo webhook 通知,您可以 post-处理预填充的 wufoo 表单发送给您的 "trimmed" url(只有 1 个斜杠的表单)以确保添加在将 url 保存到数据库(或其他)之前的第二个斜杠。为此,我使用如下 ruby 函数:

def fix_wufoo_bug(url)
    url.gsub!(':/','://') if url.match(/https?:\/\//).nil?
    return url
end

刚刚收到 Wufoo 技术支持的答复(星期天的问题很快!):

Thanks for reaching out. Sorry to hear you're having issues with this. the URL mods do work with the /, but if you put multiple together, it can only display the first one. Sorry for the bad news on that one. I'm afraid there's not a workaround to make that work even if you were to use a different field such as a single line text field.

What you could do instead is just predefine the field with www.youtube.com rather than http://youtube.com. That way you can still add the website, but it just wouldn't have https in it. Sorry you can't do what you're wanting here. Let us know if you have any other questions.

Best,

看来这确实是一个bug,而且没有正确的方法来做到这一点。