Jump to content

Translate First Namen and Last Name in contact form

Recommended Posts

Hi, 
I'm using square space for the first time and I have never coded before so I hope you guys can help me.  I'm trying to translate the hard coded labels in the contact form on our web page https://padelakersberga.com/kontakt-1

I tried with this code, but it didnt work:

<script>  
  if (document.querySelector("#name-yui_3_17_2_1_1553888888520_3744")) {
    document.querySelector('.field-element field-control[name="fname"]').placeholder = 'Förnamn';
    document.querySelector('.field-element field-control[name="lname"]').placeholder = 'Efternamn';    
  }
</script>

Maybe I'm way off here, the code could be totally wrong, but I found some similar code while searching for answers so this is what I came up with. 

BR
Ted

Link to comment
  • Replies 5
  • Views 668
  • Created
  • Last Reply

Good attempt! Try adding this to Settings > Advanced > Code Injection > Footer instead:

<script>  
  if (document.querySelector('.form-item.fields.name')) {
    document.querySelector('.field.first-name .caption .caption-text').innerText = 'Förnamn';
    document.querySelector('.field.last-name .caption .caption-text').innerText = 'Efternamn'; 
  }
</script>

Note that like most answers, this is a simplified example and will only modify the captions on the first name field within a form.

Please Note: In May 2023, Squarespace made changes to Form Blocks. This code will no longer work as expected, but can be adapted by using different classnames.

  If this helps you, please click "Like" below  ⬇️

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Link to comment
  • 3 months later...

Hello @paul2009,

I have placed this version code

<script>  
  if (document.querySelector("#name-yui_3_17_2_1_1559593002966_3555")) {
    document.querySelector('.field.first-name .caption .caption-text').innerText = 'First name';
    document.querySelector('.field.last-name .caption .caption-text').innerText = 'Last name'; 
  }
</script>

in the PAGE HEADER CODE INJECTION of a certain page in order to only change it there, but nothing happened. Then I went on and put it onto the global footer code injection and then it change BUT unfortunately for all pages. I would like to have it only on my English contanct form.

Do you know how I can accomplish that? I am working on stelviopartners.com

thank you in advance for any kind of help, cris

Link to comment
33 minutes ago, Xbal said:

I would like to have it only on my English contact form. Do you know how I can accomplish that?

There are a number of ways to do this. The simplest way should be to add a Code Block to this page, placing it below the Form Block. Add the code to the Code Block instead. 

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Link to comment
46 minutes ago, Xbal said:

Which are the other ways if I may ask?

You can limit to the page by checking the collection ID or the page URL slug.

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.