Squarespace unique identifier solution no longer works due to change in form. Need help to determine why it wont work/solution

huangapple go评论56阅读模式
英文:

Squarespace unique identifier solution no longer works due to change in form. Need help to determine why it wont work/solution

问题

以下是您要翻译的部分:

"SS=Square Space

Previously there was a script posted by Ian_A on the SS forums to add in a unique identifier on forms submitted to prevent collation of emails in gmail. This enabled us to reply to each received form by hitting reply without needing to alter our default gmail box to conversation view etc.

We cannot change our gmail settings. (cannot turn on conversation view without alienating some users)

SS have since changed how the forms work and I believe that the $ parameter of the script no longer targets the correct part of the field. I don't have a coding background, my limited understanding is that the $ is the way jquery selects the field. I am not sure how to structure the jquery selector to pick the field I want by perhaps the class ID which is unique to each field on the form.

There is only one form to make this work on. I only have access to header code injection and custom CSS. I need each email sent by the form to have a randomised subject (or time/date stamped)

Below is the example of the code that worked prior to SS updating the site."

来源= SS论坛帖子

Our website contact us page= 要使用的表单

Below is the information I can see relating to the blank subject text box I both wish to hide from the user and autofill with a unique identifier on send so that we can identify each send individually. I feel there should be a way with jquery to get it to pick this instead of the just the first field on the form which no longer works, but I can't work out how to change the previous code above, to make it work and despite testing can't see why it wont work (no errors throw on the page load and I don't know how else to check)

For example: $('form') .find(input.text-dfd9bd71-70a1-413d-81f2-dae19bb38da2 )

I know this doesn't work but I don't know why it doesn't work, I feel like it could use the div id, or class but idk how to make jquery do that and the documentation is above my understanding currently."

上面是您要翻译的内容。

英文:

SS=Square Space

Previously there was a script posted by Ian_A on the SS forums to add in a unique identifier on forms submitted to prevent collation of emails in gmail. This enabled us to reply to each received form by hitting reply without needing to alter our default gmail box to conversation view etc.

We cannot change our gmail settings. (cannot turn on conversation view without alienating some users)

SS have since changed how the forms work and I believe that the $ parameter of the script no longer targets the correct part of the field. I don't have a coding background, my limited understanding is that the $ is the way jquery selects the field. I am not sure how to structure the jquery selector to pick the field I want by perhaps the class ID which is unique to each field on the form.

There is only one form to make this work on. I only have access to header code injection and custom CSS. I need each email sent by the form to have a randomised subject (or time/date stamped)

Below is the example of the code that worked prior to SS updating the site.

<script>
$(document).ready(function(){ 
    var timecode = Date.now();
    var subjecttxt = "#" + timecode;
  
  $('form').find("input[type=text], text").each(function()
  {
      if(!$(this).val()) { 
     $(this).attr("value", subjecttxt);
     $(this).attr("readonly", true);
     $(this).css("display","none");
        var val = subjecttxt;
        return ( val !== subjecttxt );
  }
  });
});

  $(document).ready(function(){ 
$('form').find("label[class=title]").each(function()
  {
      if(!$(this).val()) { 
     $(this).css("display","none");
        var val2 = "none";
        return ( val2 !== "none" );
  }
  });
});  
 </script>

Source= SS Forum Post
Our website contact us page= Form in question

Below is the information I can see relating to the blank subject text box I both wish to hide from the user and autofill with a unique identifier on send so that we can identify each send individually. I feel there should be a way with jquery to get it to pick this instead of the just the first field on the form which no longer works, but I can't work out how to change the previous code above, to make it work and despite testing can't see why it wont work (no errors throw on the page load and I don't know how else to check)

For example: $('form') .find(input.text-dfd9bd71-70a1-413d-81f2-dae19bb38da2 )

I know this doesn't work but I don't know why it doesn't work, I feel like it could use the div id, or class but idk how to make jquery do that and the documentation is above my understanding currently.

              <div id="text-dfd9bd71-70a1-413d-81f2-dae19bb38da2" class="form-item field text">
                
            <label class="title" for="text-dfd9bd71-70a1-413d-81f2-dae19bb38da2-field">
              Subject
              
            </label>
          
                
                <input
                    class="field-element text"
                    type="text"
                    id="text-dfd9bd71-70a1-413d-81f2-dae19bb38da2-field"
                    
                    
                />
              </div>

I tried to hide a section at the top of a Squarespace contact form and have jquery select the box adding in a unique identifier.

Due to a change in the SS forms this no longer works as expected.

答案1

得分: 0

很不幸,问题在于对于新的Squarespace表单块,Squarespace现在密切管理每个字段中的值,并基于实际用户输入事件(可能使用React、虚拟/影子DOM和isTrusted事件属性)持续维护这些值。这意味着,虽然您可以使用JavaScript设置字段的值,但这样做对Squarespace最终提交的值没有任何影响。并且Squarespace会在每次用户操作后(在另一个字段中输入、提交表单等)相应地重置表单字段的值。

因此,我认为这不能通过JavaScript来解决。但在旧的、未经编辑的表单块上可能有效。

除了使用第三方表单服务(如Google Forms、JotForm等),还有一种替代方法:强制使“主题”字段看起来像是“姓名”字段。您可以通过执行以下步骤来实现:

  1. 从表单中删除“姓名”字段。
  2. 确保“主题”字段是表单中的第一个字段。
  3. 在页面特定的头部注入中添加以下内容:
<style>
.form-item:first-child span {
  font-size: 0;
}
.form-item:first-child span:after {
  content: "姓名(必填)";
  font-size: 18px;
}
</style>

现在,“主题”字段将看起来像是标题为“姓名”的单个字段(而不是两个,名字和姓氏)。当提交时,电子邮件主题将类似于:“表单提交 - 联系人 - John Smith”。但在电子邮件正文中,您将看到:“主题:John Smith”。这是因为我们只是使用CSS使第一个字段看起来像是“姓名”。

确保将“主题”字段设置为必填。并删除您可能已添加的其他设置“主题”值的脚本。

当然,如果两个人输入相同的姓名,这些电子邮件可能会被合并。

此外,请考虑到错误消息(例如,如果用户将第一个字段留空并尝试提交表单)可能会对用户造成一些困惑。

这有点愚蠢的权宜之计。但如果您真的只关心电子邮件主题行,那么这可能适合您。

英文:

Unfortunately, the issue is that, for new Squarespace form blocks, Squarespace now closely manages the values in each field and persistently maintains them based only off of actual user input events (probably using React, virtual/shadow DOM and the isTrusted event property). That means that, although you can set a field value with JavaScript, doing so will have no effect on the value that Squarespace will ultimately submit. And Squarespace will correspondingly reset the form field value after every user action (typing in another field, submitting the form, etc.)

Therefore, I don't think this can be solved with JavaScript. It might work on older, unedited form blocks though.

Besides using a third-party form service (Google Forms, JotForm, etc.), there is one other alternative: Force the "Subject" field to appear as if it is the "Name" field. You'd do this by doing the following:

  1. Remove the Name field from the form.
  2. Ensure the "Subject" field is the first field in the form.
  3. Add the following to page-specific header injection:

<br>

&lt;style&gt;
.form-item:first-child span {
  font-size: 0;
}
.form-item:first-child span:after {
  content: &quot;Name (required)&quot;;
  font-size: 18px;
}
&lt;/style&gt;

Now, the "Subject" field will appear to be titled "Name" and will just be a single field (instead of two, first and last). When submissions come through, the email subject will be something like: "Form Submission - Contact - John Smith". But in the body of the email you'd see "Subject: John Smith". That's because we're just make the first field appear to be "Name" with CSS.

Be sure to set the "Subject" field to be required. And remove the other scripts you might have added to set the "Subject" value.

And of course, if two people enter the same name, those emails might be collated.

Also, consider that error messages (such as if the user leaves that first field empty and tries to submit the form) might be a little confusing to the user.

That's a bit of a silly workaround. But if all you really care about is that email subject line, it might work for you.

huangapple
  • 本文由 发表于 2023年6月5日 18:42:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定