-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-to-civi.html
executable file
·66 lines (56 loc) · 2.89 KB
/
post-to-civi.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>
// Even if the post succeeds, jQuery thinks there was an error, so we use 'complete' instead of 'success'
// Either CiviCRM is doing something weird, or this is a function of our aliasing setup
(function() {
var emailPattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
var isValidEmail = function(email) {
return email && emailPattern.test(email);
};
var notify = function(message) {
jQuery('#civi_email_result > span').html(message).css({padding: '5px', backgroundColor: '#2F5', borderRadius: '10px', marginTop: '5px', textAlign: 'center'});
setTimeout(function() {
jQuery('#civi_email_result > span').fadeOut('slow');
}, 5000);
};
var complete = function(xhr, status) {
notify('Thanks for signing up!');
};
var postToCivi = function(email) {
var profileId = -1; // Get this from Civi
var groupId = -1; // Get this from Civi
var url = 'http://crm.occupywallstreet.net/civicrm/profile/create?gid=' + profileId + '&reset=1';
var data = {
'postURL': '',
'cancelURL': '',
'add_to_group' : groupId,
'email-Primary' : email,
'_qf_default' : '',
'_qf_Edit_next' : ''
};
jQuery.ajax({
'url': url,
'data': data,
'type': 'POST',
'complete': complete
});
}
jQuery(function() {
jQuery('#submit_email_to_civi').click(function() {
var email = jQuery('#email_for_civi').val();
if (isValidEmail(email)) {
postToCivi(email);
jQuery('#email_for_civi').val('');
}
else {
notify('Please enter a valid email address.');
}
})
});
})();
</script>
<div id='join_newsletter'>
<input id='email_for_civi' type='text' placeholder="Your E-mail" />
<input id='submit_email_to_civi' type='submit' value='Submit' style='font-size: 80%' />
<div id="civi_email_result"><span> </span></div>
</div>