The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Pre-check lists on sign-up page

Highlighted

Pre-check lists on sign-up page

We have a sign-up page that was created in the "List Growth Tools" section of the Web site. We'd like to be able to create a link from our site that will load the sign-up page and automatically check specific boxes (perhaps we'd pass these in via the URL as QueryString options?). Is that a possibility?

2 REPLIES 2
Highlighted
Moderator

Re: Pre-check lists on sign-up page

Hello,

 

Thank you for reaching out to the API Support team here at Constant Contact.

 

There isn't a way to do this built-in to the embedded signup form code directly, however this may be possible by using javascript on your page. Consider something like this:

 

var i = document.location.href.lastIndexOf('?');
var types = document.location.href.substr(i+1).replace(/list=/g,'').split('&');
$('input[name="listId"]').prop('checked',function(){
     return $.inArray(this.value,types) !== -1;
});

Consider the url is 'http://mysite.com/signup.html?list=1&list=2' 

  • i is set to be the index of '?' in the url
  • .substr() removes all but 'list=1&list=2' from the url, giving us the string:
    "list=1&list=2"
  • .replace() removes the "list=" text from the string leaving us with:
    "1&2"
  • .split() splits that string into an array with the values:
    ["1","2"]
  • $.inArray() checks whether value of checkbox named "listID" is in the ["1","2"] array. If it is, then it checks the "listID" checkbox.

This would need customization to work with your form's fields and how your URL parameters are set up, but this should get you started in the right direction.

 

Please let me know if you have any other questions!

 

Sincerely,

David B.

API Support Specialist

 

Highlighted

Re: Pre-check lists on sign-up page

You're right that this didn't work 100% out of the box but it put me on the right track. Apparently on our embed form the checkboxes aren't named 'listId' but this seems to do it:

 

$(function () {
    var i = document.location.href.lastIndexOf('?');
    var types = document.location.href.substr(i + 1).replace(/list=/g, '').split('&');
    $('input[type=checkbox]').each(function () {
        $(this).prop("checked", $.inArray(this.name.match(/\d+/)[0], types) !== -1)
    });
});

Thanks so much!

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured