Last active
July 20, 2016 20:08
-
-
Save dangerouse/1585693 to your computer and use it in GitHub Desktop.
CloudSponge Widget Reference - Including mailing addresses in contacts data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<!-- | |
Include the script anywhere on your page, usually in the head | |
(don't forget to replace `localhost-only` with your own CloudSponge Widget Key) | |
--> | |
<script src="//api.cloudsponge.com/widget/localhost-only.js"></script> | |
<script> | |
// extra widget options: | |
cloudsponge.init({ | |
include:['mailing_address','name','email'], | |
afterSubmitContacts: function(contacts, source, owner) { | |
// contacts array is a set of objects that each may have an address property that | |
// is an array of mailing addresses if the contact has 1 or more mailing addresses | |
// and is undefined or null if the contact has 0 mailing addresses | |
// e.g. | |
// contacts[0].address // => undefined | |
// contacts[1].address // => Array[1] | |
// inspect the contact's name, email, phone and mailing address | |
var i, contact, name, email, phone, mailing_address; | |
for (i = 0; i < contacts.length; i++) { | |
contact = contacts[i]; | |
name = contact.fullName(); | |
email = contact.selectedEmail(); | |
phone = contact.phone[0] && contact.phone[0].number; | |
mailing_address = contact.address[0] && contact.address[0].formatted; | |
// now that we have the contact information, let's do something interesting with it.. | |
// we could add it to a form to submit to the server, | |
// or create some html on the page to display it to our user, | |
// or whatever! | |
} | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<a class="cloudsponge-launch">Add from Address Book</a> | |
<textarea class="cloudsponge-contacts"></textarea> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment