简体   繁体   English

Gatsby 在 react-helmet 中嵌入带有脚本标签的表单

[英]Gatsby embed forms with script tag in react-helmet

I am trying to embed some forms using react helmet.我正在尝试使用反应头盔嵌入一些表格。

My code looks like this:我的代码如下所示:

<Helmet>
         <script type="text/javascript">
            {var FORMID;
            (function(d, t) {
              var s = d.createElement(t), options = { 'userName':'USERNAME', 'formHash':'FORMID', 'autoResize':true, 'height':'751', 'async':true, 'host':'wufoo.com', 'header':'show', 'ssl':true };
              s.src = ('https:' == d.location.protocol ?'https://':'http://') + 'secure.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 {
                  FORMID = new WufooForm();
                  FORMID.initialize(options);
                  FORMID.display();
                } catch (e) { }
              };
              var scr = d.getElementsByTagName(t)[0], par = scr.parentNode;
              par.insertBefore(s, scr);
            })(document, 'script');}
          </script>
</Helmet>

The script is a copy and paste from wufoo form builder.该脚本是来自 wufoo 表单生成器的复制和粘贴。 (I replaced the username and form id with the all caps FORMID and USERNAME). (我用全部大写的 FORMID 和 USERNAME 替换了用户名和表单 ID)。

I keep running into errors.我一直遇到错误。 Right now this will produce a graphql error (there is not graphql in the page)现在这将产生一个graphql错误(页面中没有graphql)

There was a problem parsing "/../my-page"; any GraphQL
fragments or queries in this file were not processed.

This may indicate a syntax error in the code, or it may be a file type
that Gatsby does not know how to parse.

and a Module build failed error.和一个Module build failed错误。

In VS code I get some warnings on the var's saying expression expected .在 VS 代码中,我收到一些关于 var 的expression expected的警告。 And some other spots where it expects a { or a }.以及其他一些需要 { 或 } 的地方。 I'm pretty certain the brackets all match up.我很确定括号都匹配。 Again, it's copy and paste from wufoo and this works in plain html/js.同样,它是从 wufoo 复制和粘贴的,并且可以在纯 html/js 中使用。

Wrap your script with backticks ( ` ):用反引号 ( ` ) 包装你的脚本:

<Helmet>
         <script type="text/javascript">
            {`var FORMID;
            (function(d, t) {
              var s = d.createElement(t), options = { 'userName':'USERNAME', 'formHash':'FORMID', 'autoResize':true, 'height':'751', 'async':true, 'host':'wufoo.com', 'header':'show', 'ssl':true };
              s.src = ('https:' == d.location.protocol ?'https://':'http://') + 'secure.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 {
                  FORMID = new WufooForm();
                  FORMID.initialize(options);
                  FORMID.display();
                } catch (e) { }
              };
              var scr = d.getElementsByTagName(t)[0], par = scr.parentNode;
              par.insertBefore(s, scr);
            })(document, 'script');`}
          </script>
</Helmet>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM