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...
- <div id="wrapper"> <p>Send us feedback from the modal window.</p>
- <p><a class="modalbox" href="#inline">click to open</a></p>
- </div>
- <!-- hidden inline form -->
- <div id="inline">
- <h2>Send us a Message</h2>
- <form id="contact" name="contact" action="#" method="post">
- <label for="email">Your E-mail</label>
- <input type="email" id="email" name="email" class="txt">
- <br>
- <label for="msg">Enter a Message</label>
- <textarea id="msg" name="msg" class="txtarea"></textarea>
-
- <button id="send">Send E-mail</button>
- </form>
- </div>
- <!-- basic fancybox setup -->
- <script type="text/javascript">
- function validateEmail(email) {
- 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,}))$/;
- return reg.test(email);
- }
- $(document).ready(function() {
- $(".modalbox").fancybox();
- $("#contact").submit(function() { return false; });
-
- $("#send").on("click", function(){
- var emailval = $("#email").val();
- var msgval = $("#msg").val();
- var msglen = msgval.length;
- var mailvalid = validateEmail(emailval);
-
- if(mailvalid == false) {
- $("#email").addClass("error");
- }
- else if(mailvalid == true){
- $("#email").removeClass("error");
- }
-
- if(msglen < 4) {
- $("#msg").addClass("error");
- }
- else if(msglen >= 4){
- $("#msg").removeClass("error");
- }
-
- if(mailvalid == true && msglen >= 4) {
- // if both validate we attempt to send the e-mail
- // first we hide the submit btn so the user doesnt click twice
- $("#send").replaceWith("<em>sending...</em>");
-
- $.ajax({
- type: 'POST',
- url: 'sendmessage.php',
- data: $("#contact").serialize(),
- success: function(data) {
- if(data == "true") {
- $("#contact").fadeOut("fast", function(){
- $(this).before("<p><strong>Success! Your feedback has been sent, thanks :)</strong></p>");
- setTimeout("$.fancybox.close()", 1000);
- });
- }
- }
- });
- }
- });
- });
- </script>
Above solution uses Fancybox.
Any help or advice would be hugely appreciated
Adam