No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

form.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. $(document).ready(function () {
  2. let formHTML = ` <!-- pop up -->
  3. <!-- enquire-form pop up -->
  4. <div class="modal fade style" id="enquireModal" tabindex="-1" role="dialog">
  5. <div class="modal-dialog modal-dialog-centered" role="document">
  6. <div class="wrap-contact100">
  7. <div class="modal-content contact100-form validate-form">
  8. <div class=" justify-content-center ">
  9. <!-- <h5 class="modal-title" id="itemTitle"> </h5> -->
  10. <button type="button" class="close" data-bs-dismiss="modal" >
  11. <span >&times;</span>
  12. </button>
  13. </div>
  14. <div class="row w-100">
  15. <div class="enquire-form-img col-md-6 col-12">
  16. </div>
  17. <div class="enquire-form col-md-6 col-12 py-5 px-30">
  18. <div>
  19. <h3 class="contact-page-title">Request a Quote</h3>
  20. </div>
  21. <div>
  22. <div id="pageloader" class="d-none">
  23. <img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif"
  24. alt="processing..." />
  25. </div>
  26. <form id="anwi-enquire-form" method="POST" action="quote-request.php">
  27. <div class="form-floating ">
  28. <input type="text" class="form-control" id="userName" name="name" placeholder="name@example.com" onblur="submit_enquiry()" required>
  29. <label for="name">Your Name</label>
  30. </div>
  31. <div class="form-floating">
  32. <input type="text" class="form-control" id="itemTitle" name="Title" placeholder="Password" disabled>
  33. <label for="name">Product</label>
  34. </div>
  35. <div class="form-floating ">
  36. <input type="email" class="form-control" id="floatingEmail" name="email" placeholder="name@example.com" onblur="submit_enquiry()" required>
  37. <label for="floatingEmail">Email address</label>
  38. </div>
  39. <div class="form-floating">
  40. <input type="number" class="form-control" id="floatingPhonenumber" name="phone" placeholder="Password" onblur="submit_enquiry()" required>
  41. <label for="floatingPhonenumber">Mobile No</label>
  42. </div>
  43. <div class="form-floating ">
  44. <input type="text" class="form-control" id="floatingSubject" name="subject" placeholder="name@example.com" required>
  45. <label for="floatingSubject">Subject</label>
  46. </div>
  47. <div class="form-floating">
  48. <textarea name="contactMessage" class="form-control" id="contactMessage" name="message" placeholder="Your Message" required style="height:100px"></textarea>
  49. <label for="floatingPassword">Message</label>
  50. </div>
  51. <div class="form-floating text-center my-4">
  52. <button type="submit" value="submit" id="submitbtn" class="btn btn-primary btn--lg " name="submit" onclick="submit_enquiry()">
  53. submit
  54. </button>
  55. </div>
  56. </form>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <!-- end popup -->`;
  65. $("#enquire").html(formHTML);
  66. // Document is ready
  67. $(document).ready(function () {
  68. // Validate Username
  69. $("#usercheck").hide();
  70. let usernameError = true;
  71. $("#usernames").keyup(function () {
  72. validateUsername();
  73. });
  74. function validateUsername() {
  75. let usernameValue = $("#usernames").val();
  76. if (usernameValue.length == "") {
  77. $("#usercheck").show();
  78. usernameError = false;
  79. return false;
  80. } else if (usernameValue.length < 3 || usernameValue.length > 10) {
  81. $("#usercheck").show();
  82. $("#usercheck").html("*length of username must be between 3 and 10");
  83. usernameError = false;
  84. return false;
  85. } else {
  86. $("#usercheck").hide();
  87. }
  88. }
  89. // Validate Email
  90. const email = document.getElementById("email");
  91. email.addEventListener("blur", () => {
  92. let regex = /^([_\-\.0-9a-zA-Z]+)@([_\-\.0-9a-zA-Z]+)\.([a-zA-Z]){2,7}$/;
  93. let s = email.value;
  94. if (regex.test(s)) {
  95. email.classList.remove("is-invalid");
  96. emailError = true;
  97. } else {
  98. email.classList.add("is-invalid");
  99. emailError = false;
  100. }
  101. });
  102. // Submit button
  103. $("#submitbtn").click(function () {
  104. validateUsername();
  105. validateEmail();
  106. if (
  107. usernameError == true &&
  108. passwordError == true &&
  109. emailError == true
  110. ) {
  111. return true;
  112. } else {
  113. return false;
  114. }
  115. });
  116. });
  117. function pop_up() {
  118. let title = $(".single-product-head").find(".title").text();
  119. // $('#itemTitle').text(title);
  120. // console.log(title);
  121. $("#itemTitle").val(title);
  122. }
  123. function submit_enquiry() {
  124. // alert("awsdfa");
  125. if (enquire_form.name.value.length == 0) {
  126. document.getElementById("errName");
  127. }
  128. if (enquire_form.email.value.length == 0) {
  129. document.getElementById("errEmail");
  130. }
  131. }
  132. pop_up();
  133. submit_enquiry();
  134. $("#anwi-enquire-form").validate({
  135. rules: {
  136. phone: {
  137. minlength: 10,
  138. maxlength: 10,
  139. number: true,
  140. },
  141. },
  142. submitHandler: function (form) {
  143. loader();
  144. $.ajax({
  145. type: "POST",
  146. url: "quote-request.php",
  147. data: $(form).serialize(),
  148. success: function (res) {
  149. if (res == 1) {
  150. toastr.success("Form Submitted Successfully!");
  151. $(form).trigger("reset");
  152. $(form)
  153. .find(".form-control-placeholder")
  154. .removeClass("floating-label");
  155. $("#pageloader").remove();
  156. $("#anwi-enquire-form").removeClass("d-none");
  157. } else {
  158. toastr.error("Something Went Wrong,Try Again!");
  159. $("#pageloader").remove();
  160. $("#anwi-enquire-form").removeClass("d-none");
  161. }
  162. },
  163. });
  164. return false;
  165. },
  166. });
  167. function loader() {
  168. //$("#biz-contact-form").on("submit", function () {
  169. $("#pageloader").fadeIn();
  170. $("#anwi-enquire-form").addClass("d-none");
  171. //});
  172. //submit
  173. }
  174. });