Advertisement
quokka

Sendy.co ajax subscription / unsubscription form

Apr 18th, 2013
2,591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. STEP 1
  2. --------------------------------------------------------------------
  3. >> In both files subscribe.php and unsubscribe.php in your Sendy root directory
  4. on top, just below <?php, add:
  5.  
  6. header('Access-Control-Allow-Origin: *');
  7.  
  8. Same files, find:
  9.  
  10. ?>
  11. <!DOCTYPE html>
  12.  
  13. >> Change this to:
  14.  
  15. // custom mod for ajax subscription form
  16. if(isset($_POST['do_ajax'])){
  17. echo json_encode(strip_tags($feedback));
  18. exit();
  19. }
  20.  
  21. ?>
  22. <!DOCTYPE html>
  23.  
  24.  
  25. STEP 2
  26. --------------------------------------------------------------------
  27. >> Save the code below in a new file, name it "subscribe_ajax.php" and save it in your Sendy root directory
  28.  
  29. <?php
  30. // configuration | change these values to reflect your list
  31. $list = "UZiGZ22lF1njeyaAt763csaw";
  32. $sendy_url = "http://scripturlhere.com";
  33. $purpose = "subscribe" // (subscribe OR unsubscribe) // is this a subscribe or unsubscribe form?
  34. ?>
  35.  
  36. <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  37. <script type="text/javascript">
  38. $(document).ready(function(){
  39. $("#message").html('');
  40. $("#subscription_form").submit(function(){
  41. $("#message").html('');
  42. var name = $('input[name=name]').val();
  43. var list = $('input[name=list]').val();
  44. var email = $('input[name=email]').val();
  45.  
  46. var querystring = "name="+name+"&email="+email+"&list="+list+"&do_ajax=yes";
  47. $.ajax({
  48. url: 'http://newsletter.zwembad.eu/<?php echo $purpose; ?>.php',
  49. type: "POST",
  50. data: querystring,
  51. success: function(data) {
  52. $("#message").html(data);
  53. }
  54. });
  55. return false;
  56. });
  57. });
  58. </script>
  59.  
  60. <div id="message"></div>
  61. <form id="subscription_form" action="<?php echo $sendy_url; ?>/<?php echo $purpose; ?>.php" method="POST" accept-charset="utf-8">
  62. <?php if($purpose=="subscribe"){ ?>
  63. <label for="name">Name</label><br/>
  64. <input type="text" name="name" id="name"/>
  65. <br/>
  66. <?php } ?>
  67. <label for="email">Email</label><br/>
  68. <input type="text" name="email" id="email"/>
  69. <br/>
  70. <input type="hidden" name="list" value="<?php echo $list; ?>"/>
  71. <input type="submit" name="submit" id="submit"/>
  72. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement