Guest User

Enquiry form with validation & facebox

a guest
Jan 20th, 2012
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. <script language="JavaScript">
  2. <!--
  3.  
  4. /***********************************************
  5. * Required field(s) validation v1.10- By NavSurf
  6. * Visit Nav Surf at http://navsurf.com
  7. * Visit http://www.dynamicdrive.com/ for full source code
  8. ***********************************************/
  9.  
  10. function formCheck(formobj){
  11. // Enter name of mandatory fields
  12. var fieldRequired = Array("name", "email", "tel", "address", "country");
  13. // Enter field description to appear in the dialog box
  14. var fieldDescription = Array("Name", "Email", "Telephone", "Address", "Country");
  15. // dialog message
  16. var alertMsg = "Please complete the following fields:\n";
  17.  
  18. var l_Msg = alertMsg.length;
  19.  
  20. for (var i = 0; i < fieldRequired.length; i++){
  21. var obj = formobj.elements[fieldRequired[i]];
  22. if (obj){
  23. switch(obj.type){
  24. case "select-one":
  25. if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
  26. alertMsg += " - " + fieldDescription[i] + "\n";
  27. }
  28. break;
  29. case "select-multiple":
  30. if (obj.selectedIndex == -1){
  31. alertMsg += " - " + fieldDescription[i] + "\n";
  32. }
  33. break;
  34. case "text":
  35. case "textarea":
  36. if (obj.value == "" || obj.value == null){
  37. alertMsg += " - " + fieldDescription[i] + "\n";
  38. }
  39. break;
  40. default:
  41. }
  42. if (obj.type == undefined){
  43. var blnchecked = false;
  44. for (var j = 0; j < obj.length; j++){
  45. if (obj[j].checked){
  46. blnchecked = true;
  47. }
  48. }
  49. if (!blnchecked){
  50. alertMsg += " - " + fieldDescription[i] + "\n";
  51. }
  52. }
  53. }
  54. }
  55.  
  56. if (alertMsg.length == l_Msg){
  57. return true;
  58. }else{
  59. alert(alertMsg);
  60. return false;
  61. }
  62. }
  63. // -->
  64. </script>
  65.  
  66. <script>
  67. function quoteme() {
  68. $("#msgbox_body").html('<div id="contactform" style="margin-left:20px;margin-right:20px;margin-top:10px;"><form class="form" onsubmit="return formCheck(this);" method="POST" action="http://www.dtrmedical.com"><table border="0"><tbody><tr><td><p class="name"><label for="name">Your Name<span style="color:red;">*</span>:</label></p></td><td>&nbsp;</td><td><input type="text" name="name" id="name" /></td></tr><tr><td><p class="hospital"><label for="hospital">Hospital/Institution:</label></p></td><td>&nbsp;</td><td><input type="text" name="hospital" id="hospital" /></td></tr><tr><td><p class="department"><label for="department">Department:</label></p></td><td>&nbsp;</td><td><input type="text" name="department" id="department" /></td></tr><tr><td><p class="address"><label for="address">Address<span style="color:red;">*</span>:</label></p></td><td>&nbsp;</td><td><input type="text" name="address" id="address" /></td></tr><tr><td><p class="country"><label for="country">Country<span style="color:red;">*</span>:</label></p></td><td>&nbsp;</td><td><input type="text" name="country" id="country" /></td></tr><tr><td><p class="email"><label for="email">E-mail<span style="color:red;">*</span>:</label></p></td><td>&nbsp;</td><td><input type="text" name="email" id="email" /></td></tr><tr><td><p class="tel"><label for="tel">Telephone<span style="color:red;">*</span>:</label></p></td><td>&nbsp;</td><td><input type="text" name="tel" id="tel" /></td></tr><tr><td colspan="3" align="center"><p class="submit"><input style=\"margin-left:27px;cursor:pointer;\" onClick="jQuery.facebox({ ajax: (\'wishlist.php?emailme=true&name=\' + this.form.name.value + \'&country=\' + this.form.country.value + \'&email=\' + this.form.email.value + \'&address=\' + this.form.address.value + \'&tel=\' + this.form.tel.value + \'&hospital=\' + this.form.hospital.value + \'&department=\' + this.form.department.value) }); return false;" type="submit" value="Send enquiry" name="submit" /></p></td><td>&nbsp;</td><td>&nbsp;</td></tr></tbody></table></form></div>');
  69. $("#msgbox_actions").html('<input onclick="jQuery.facebox({ ajax: \'wishlist.php?basket=true\' })" type="button" value="Back to Wishlist" />');
  70. }
  71. </script>
  72. <? if (!$listempty) { ?>
  73. <div id="msgbox_actions"><input onclick="quoteme()" type="button" value="Request quote/sample" /> <a class="backtoproducts" href="http://www.dtrmedical.com/products" style="border-bottom-left-radius:5px 5px;border-bottom-right-radius:5px 5px;border-bottom-style:none;border-color:initial;border-left-style:none;border-right-style:none;border-top-left-radius:5px 5px;border-top-right-radius:5px 5px;border-top-style:none;border-width:initial;color:white;font-family:Arial;padding-bottom:2px;padding-left:6px;padding-right:6px;padding-top:2px;font-size:11px;">Back to products</a></div><!-- <input type="submit" value="Update" /> --><!-- <input onclick="jQuery.facebox({ ajax: 'wishlist.php?emailme=true' })" type="button" value="Save list for later" /> --> <!-- <input type="submit" value="Update Qty's" /> <input onclick="jQuery.facebox({ ajax: 'wishlist.php?basket=true&clearall=true' })" type="button" value="Clear list" /> -->
  74. <? } ?>
  75. </form>
  76. <? } //REMOVED </div> just before here ?>
  77.  
  78. <?php
  79. // if send email
  80. if(isset($_GET['emailme']) && $_GET['emailme'] == 'true') {
  81. // to and subject
  82. $subject = "DTR Medical website - Product enquiry";
  83.  
  84. // get these from query string
  85. $name_field = $_GET['name'];
  86. $hospital_field = $_GET['hospital'];
  87. $address_field = $_GET['address'];
  88. $country_field = $_GET['country'];
  89. $department_field = $_GET['department'];
  90. $email_field = $_GET['email'];
  91. $tel_field = $_GET['tel'];
  92.  
  93. // get wishlist
  94. $query = "SELECT w.*, p.product_name, q.quantity_name, o.product_code, o.description
  95. FROM wishlistbasket w, products p, product_quantities q, product_options o
  96. WHERE sesid = '$sesid' AND w.pid = p.id AND w.qid = q.id AND w.oid = o.id ORDER BY w.pid, w.qid, w.oid";
  97. $res = mysql_query($query);
  98. $wish_list = '';
  99. if($res){
  100. while($row = mysql_fetch_assoc($res)) {
  101. if ($row['qty'] == 1) {
  102. $row['qty'] = "Quote";
  103. } else if ($row['qty'] == 2) {
  104. $row['qty'] = "Sample";
  105. } else if ($row['qty'] == 3) {
  106. $row['qty'] = "Quote and Sample";
  107. }
  108. $wish_list .= $row['product_code'] . ' - ' . $row['product_name'] . ', ' . $row['quantity_name'] . ', ' . $row['qty'] . '' . $row['product_options'] . "
  109. \n";
  110. }
  111. }
  112.  
  113. // build mail body
  114. $body = "DTR Medical,\n\n
  115. You have an enquiry from the website, please see the details below:\n\n
  116. Name: $name_field\n
  117. Hospital/institution: $hospital_field\n
  118. Department: $department_field\n
  119. Address: $address_field\n
  120. Country: $country_field\n
  121. E-Mail: $email_field\n
  122. Tel: $tel_field\n
  123. Wishlist:\n $wish_list";
  124. mail($to, $subject, $body);
  125. echo "<div style=\"margin:20px;\">Thank you for your enquiry. We will be in touch within 48 hours.<br /> <br />If you would like to get in touch regarding your enquiry then please call us on:<br /> +44 (0) 1792 79 79 10<br /><br /><div onclick=\"location.href='/products\" style=\"margin-left:135px;cursor: pointer; margin-top: 10px; border-top-left-radius: 5px 5px; border-top-right-radius: 5px 5px; border-bottom-right-radius: 5px 5px; border-bottom-left-radius: 5px 5px; background-color:#663399; width: 143px; height: 30px;\"><a style=\" color:white;display:block;float:right;height:26px;margin-top:4px;padding-left:0px;padding-top:5px;width:120px;\" href=\"/products\" class=\"basket\">Back to products</a></div></div>";}
  126. ?>
Advertisement
Add Comment
Please, Sign In to add comment