Jump to content

[Share] How to add a Checkbox to Newsletter Block

Recommended Posts

Posted

If you want to add a checkbox to Newsletter, users need to check it before clicking submit button.

image.png.cff8339a364f30933e9858758ec832a3.png

You can follow these.

#1. Find ID of Newsletter Block.

In my example, it is: #block-yui_3_17_2_1_1732180734113_20813

image.png.67ba3ab0b928bc3cf6517d96e8bd65c2.png

#2. Use this code to Code Injection Footer (or Page Header Injection)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
  var newsLetterForm = $(".newsletter-form-body")[0];
    $(newsLetterForm).find("#block-yui_3_17_2_1_1732180734113_20813 .newsletter-form-fields-wrapper").after('<label><input id="checkbox-form" type="checkbox"> I agree as per privacy policy</label>')
  var buttonSubmit = $(newsLetterForm).find("button")
  
  if($(this).is(':checked')){
        buttonSubmit.removeClass("disableButton")
    } else {
        buttonSubmit.addClass("disableButton")
    }
  
  $("#checkbox-form").change(function() {
      if($(this).is(':checked')){
        buttonSubmit.removeClass("disableButton")
    } else {
        buttonSubmit.addClass("disableButton")
    }
    });
});
</script>
<style>
#block-yui_3_17_2_1_1732180734113_20813 .newsletter-form-button.disableButton {
  background-color: gray!important;
  pointer-events: none;
}
#block-yui_3_17_2_1_1732180734113_20813 div.newsletter-form-body {
    display: flex;
    flex-direction: column;
}
</style>

image.png.fb647bf021d819fc06bda39602472cbe.png

#3. You can change Text/ID here

image.thumb.png.977997c67998980b1b720a7f274085fa.png

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

  • Replies 0
  • Views 66
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • 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.