Using 2 popup forms on same page

Using 2 popup forms on same page

Hi all

I want to have two popup forms on my site, and so far I have used this example:


This works fine with one pop up form.

Can anyone advise how I can adapt this code, so I can have two different popup forms that both work?!

Here's the code...

  1. <div id="wrapper"> <p>Send us feedback from the modal window.</p>


  2. <p><a class="modalbox" href="#inline">click to open</a></p>
  3. </div>


  4. <!-- hidden inline form -->
  5. <div id="inline">
  6. <h2>Send us a Message</h2>


  7. <form id="contact" name="contact" action="#" method="post">
  8. <label for="email">Your E-mail</label>
  9. <input type="email" id="email" name="email" class="txt">
  10. <br>
  11. <label for="msg">Enter a Message</label>
  12. <textarea id="msg" name="msg" class="txtarea"></textarea>
  13. <button id="send">Send E-mail</button>
  14. </form>
  15. </div>


  16. <!-- basic fancybox setup -->
  17. <script type="text/javascript">
  18. function validateEmail(email) { 
  19. var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  20. return reg.test(email);
  21. }


  22. $(document).ready(function() {
  23. $(".modalbox").fancybox();
  24. $("#contact").submit(function() { return false; });


  25. $("#send").on("click", function(){
  26. var emailval  = $("#email").val();
  27. var msgval    = $("#msg").val();
  28. var msglen    = msgval.length;
  29. var mailvalid = validateEmail(emailval);
  30. if(mailvalid == false) {
  31. $("#email").addClass("error");
  32. }
  33. else if(mailvalid == true){
  34. $("#email").removeClass("error");
  35. }
  36. if(msglen < 4) {
  37. $("#msg").addClass("error");
  38. }
  39. else if(msglen >= 4){
  40. $("#msg").removeClass("error");
  41. }
  42. if(mailvalid == true && msglen >= 4) {
  43. // if both validate we attempt to send the e-mail
  44. // first we hide the submit btn so the user doesnt click twice
  45. $("#send").replaceWith("<em>sending...</em>");
  46. $.ajax({
  47. type: 'POST',
  48. url: 'sendmessage.php',
  49. data: $("#contact").serialize(),
  50. success: function(data) {
  51. if(data == "true") {
  52. $("#contact").fadeOut("fast", function(){
  53. $(this).before("<p><strong>Success! Your feedback has been sent, thanks :)</strong></p>");
  54. setTimeout("$.fancybox.close()", 1000);
  55. });
  56. }
  57. }
  58. });
  59. }
  60. });
  61. });
  62. </script>
Above solution uses Fancybox. 

Any help or advice would be hugely appreciated

Adam                  
    • Topic Participants

    • adam