form-main.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <div class="news-form">
  2. <div class="text-center title">
  3. <h4>線上諮詢</h4>
  4. <p>與我們合作,馬上展開全新的創作里程碑</p>
  5. </div>
  6. <form>
  7. <div class="mb-4 align-items-center">
  8. <label for="nameValue">
  9. 聯繫人稱呼 <span class="text-danger">*</span>
  10. </label>
  11. <div class="mt-2">
  12. <input type="text" class="form-control" id="nameValue" placeholder="請留下聯繫人稱呼" required>
  13. </div>
  14. </div>
  15. <div class="row mb-4 align-items-center">
  16. <label for="phoneValue">
  17. 聯絡電話 <span class="text-danger">*</span>
  18. </label>
  19. <div class="mt-2 col-sm-4">
  20. <select id="countryCode" class="form-select">
  21. <option selected>選擇國碼</option>
  22. </select>
  23. </div>
  24. <div class="mt-3 mt-sm-2 col-sm-8">
  25. <input type="tel" class="form-control" id="phoneCode" placeholder="e.g., 988 888 888" required>
  26. </div>
  27. </div>
  28. <div class="mb-4 align-items-center">
  29. <label for="emailValue">
  30. 電子信箱 <span class="text-danger">*</span>
  31. </label>
  32. <div class="mt-2">
  33. <input type="email" class="form-control" id="emailValue" placeholder="請留下 E-mail" required>
  34. </div>
  35. <div class="invalid-feedback">
  36. Please choose a username.
  37. </div>
  38. </div>
  39. <!-- <div class="mb-4 align-items-center">
  40. <label for="dateValue">
  41. 預計執行日期 <span class="text-danger">*</span>
  42. </label>
  43. <div class="mt-2 d-flex align-items-center">
  44. <input type="date" id="dateValue" name="dateValue" class="px-2"
  45. style="border:1px solid #ced4da; border-radius: 3px;" required />
  46. </div>
  47. </div> -->
  48. <div class="mb-4 align-items-center">
  49. <label for="captionValue">
  50. 需求說明 <span class="text-danger">*</span>
  51. </label>
  52. <div class="mt-2">
  53. <textarea class="form-control" id="captionValue" rows="3" placeholder="請簡述說明" required></textarea>
  54. </div>
  55. </div>
  56. <div class="mb-4 align-items-center">
  57. <label for="companyValue">
  58. 公司名稱 (非必填)
  59. </label>
  60. <div class="mt-2">
  61. <input type="text" class="form-control" id="companyValue" placeholder="請留下公司名稱">
  62. </div>
  63. </div>
  64. <div class="mb-4 align-items-center">
  65. <label for="companyValue">
  66. LINE ID (非必填)
  67. </label>
  68. <div class="mt-2">
  69. <input type="text" class="form-control" id="lineidValue" placeholder="請留下 LINE ID">
  70. </div>
  71. </div>
  72. <div class="mt-2">
  73. <div class="form-check">
  74. <input class="form-check-input mt-2" type="checkbox" id="agreeValue">
  75. <label class="form-check-label w-100" for="agreeValue">
  76. 本人同意集仕多搜集資料
  77. </label>
  78. </div>
  79. </div>
  80. <div style="height: 15px;">
  81. <span class="errorText text-danger">尚有欄位未填寫</span>
  82. </div>
  83. <div class="d-flex justify-content-center">
  84. <button type="submit" class="submit-btn" id="submitBtn">
  85. <span class="spinner-border spinner-border-sm me-2 loading-btn" role="status" aria-hidden="true"></span>
  86. 提交
  87. </button>
  88. </div>
  89. </form>
  90. </div>
  91. <script src="//code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  92. crossorigin="anonymous"></script>
  93. <script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
  94. <script type="module">
  95. import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
  96. const supabase = createClient('http://172.105.241.163:8000', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q');
  97. // 電話國碼
  98. const countryCodes = [
  99. '+1', // 美國
  100. '+7', // 俄羅斯
  101. '+33', // 法國
  102. '+39', // 義大利
  103. '+44', // 英國
  104. '+46', // 瑞典
  105. '+47', // 挪威
  106. '+49', // 德國
  107. '+52', // 墨西哥
  108. '+60', // 馬來西亞
  109. '+61', // 澳大利亞
  110. '+62', // 印尼
  111. '+64', // 紐西蘭
  112. '+65', // 新加坡
  113. '+66', // 泰國
  114. '+81', // 日本
  115. '+82', // 南韓
  116. '+86', // 中國大陸
  117. '+91', // 印度
  118. '+353', // 愛爾蘭
  119. '+852', // 香港
  120. '+853', // 澳門
  121. '+886', // 台灣
  122. ];
  123. console.log(countryCodes);
  124. const countryCode = document.getElementById('countryCode');
  125. countryCodes.forEach(code => {
  126. const option = document.createElement('option');
  127. option.value = code;
  128. option.text = code;
  129. countryCode.appendChild(option);
  130. });
  131. $('.errorText').hide();
  132. $('.loading-btn').hide();
  133. const scriptURL = 'https://script.google.com/macros/s/AKfycbzuwioqhnP2oL0AdHaYgEBvf0t0yWi2OTxZYlPYSoLuPyHhQFJKMm5mgOCoZEx-cIckbA/exec';
  134. async function send() {
  135. console.log('addEventListener');
  136. let name = document.querySelector('#nameValue').value; // 聯絡人
  137. let phone; // 聯絡電話
  138. let company = document.querySelector('#companyValue').value; // 公司名稱
  139. let email = document.querySelector('#emailValue').value; // 電子信箱
  140. // let demand; // 需求目的
  141. let caption = document.querySelector('#captionValue').value; // 需求說明
  142. let lineid = document.querySelector('#lineidValue').value; // 需求說明
  143. // let date = document.querySelector('#dateValue').value; // 預計活動需求日
  144. let agree; // 搜集資料
  145. let time; // 填單時間
  146. // 取得當下時間
  147. const now = new Date();
  148. const options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' };
  149. time = now.toLocaleString('zh-TW', options);
  150. console.log('time', time);
  151. if (document.querySelector('input[id="agreeValue"]:checked')) {
  152. agree = "同意";
  153. } else {
  154. agree = "不同意";
  155. }
  156. // if (document.querySelector('input[name="demandValue"]:checked')) {
  157. // demand = document.querySelector('input[name="demandValue"]:checked').value;
  158. // }
  159. // if (demand === "其他") {
  160. // demand = document.querySelector('#otherText').value;
  161. // }
  162. let countryCode = document.querySelector('#countryCode').value; // 國碼
  163. let phoneCode = document.querySelector('#phoneCode').value; // 電話號碼
  164. phone = `${countryCode} ${phoneCode}`;
  165. const insertdata = {
  166. "name": name,
  167. "phone": phone,
  168. "company": company,
  169. "email": email,
  170. "lineid": lineid,
  171. "caption": caption,
  172. // "date": date,
  173. "agree": agree,
  174. "time": time
  175. }
  176. console.log(insertdata);
  177. $.ajax({
  178. url: scriptURL,
  179. method: "post",
  180. data: {
  181. "name": name,
  182. "phone": phone,
  183. "company": company,
  184. "email": email,
  185. "lineid": lineid,
  186. "caption": caption,
  187. // "date": date,
  188. "agree": agree,
  189. "time": time
  190. },
  191. success: function (response) {
  192. if (response == "成功") {
  193. $('.loading-btn').hide();
  194. alert("成功提交!");
  195. }
  196. },
  197. });
  198. }
  199. $('button').on('click', function (e) {
  200. e.preventDefault();
  201. let countryCode = document.querySelector('#countryCode').value;
  202. // let demand = ""; // 需求目的
  203. // if (document.querySelector('input[name="demandValue"]:checked')) {
  204. // demand = document.querySelector('input[name="demandValue"]:checked').value;
  205. // }
  206. // if (demand === "其他") {
  207. // demand = document.querySelector('#otherText').value;
  208. // }
  209. // 手動觸發表單提交
  210. let form = $(this).closest('form');
  211. form[0].reportValidity(); // 顯示瀏覽器內建錯誤提示
  212. if (countryCode === "選擇國碼") {
  213. console.log('表單未通過驗證');
  214. $('.errorText').show();
  215. return;
  216. }
  217. if (form[0].reportValidity()) {
  218. $('.loading-btn').show();
  219. $('.errorText').hide();
  220. send();
  221. }
  222. });
  223. </script>