form.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <div class="news-form">
  2. <div class="text-center title">
  3. <h4>線上諮詢</h4>
  4. <p>與我們合作,馬上展開全新的創作里程碑</p>
  5. </div>
  6. <form>
  7. <div class="row mb-4">
  8. <label for="nameValue" class="col-md-2 col-lg-3 col-xl-2 col-form-label">
  9. <div class="d-flex flex-nowrap">
  10. 聯絡人 <span class="text-danger">*</span>
  11. </div>
  12. </label>
  13. <div class="col-md-10 col-lg-9 col-xl-10">
  14. <input type="text" class="form-control" id="nameValue" placeholder="請留下聯絡人姓名" required>
  15. </div>
  16. </div>
  17. <div class="row mb-4">
  18. <label for="phoneValue" class="col-md-2 col-lg-3 col-xl-2 col-form-label">
  19. <div class="d-flex flex-nowrap">
  20. 聯絡電話 <span class="text-danger">*</span>
  21. </div>
  22. </label>
  23. <div class="col-sm-4 col-md-3 col-lg-4 col-xl-3">
  24. <select id="countryCode" class="form-select">
  25. <option selected>選擇國碼</option>
  26. </select>
  27. </div>
  28. <div class="col-sm-8 col-md-7 col-lg-5 col-xl-7 mt-3 mt-sm-0">
  29. <input type="tel" class="form-control" id="phoneCode" placeholder="e.g., 988 888 888" required>
  30. </div>
  31. </div>
  32. <div class="row mb-4">
  33. <label for="companyValue" class="col-md-2 col-lg-3 col-xl-2 col-form-label">
  34. <div class="d-flex flex-nowrap">
  35. 公司名稱 <span class="text-danger">*</span>
  36. </div>
  37. </label>
  38. <div class="col-md-10 col-lg-9 col-xl-10">
  39. <input type="text" class="form-control" id="companyValue" placeholder="請留下公司名稱" required>
  40. </div>
  41. </div>
  42. <div class="row mb-3">
  43. <label for="emailValue" class="col-md-2 col-lg-3 col-xl-2 col-form-label">
  44. <div class="d-flex flex-nowrap">
  45. 電子信箱 <span class="text-danger">*</span>
  46. </div>
  47. </label>
  48. <div class="col-md-10 col-lg-9 col-xl-10">
  49. <input type="email" class="form-control" id="emailValue" placeholder="請留下 E-mail" required>
  50. </div>
  51. <div class="invalid-feedback">
  52. Please choose a username.
  53. </div>
  54. </div>
  55. <div class="row mb-3">
  56. <label for="dateValue" class="col-md-2 col-lg-3 col-xl-2 col-form-label">
  57. <div class="d-flex flex-nowrap">
  58. 預計活動需求日 <span class="text-danger">*</span>
  59. </div>
  60. </label>
  61. <div class="col-md-10 col-lg-9 col-xl-10 d-flex align-items-center">
  62. <input type="date" id="dateValue" name="dateValue" class="px-2"
  63. style="border:1px solid #ced4da; border-radius: 3px;" required />
  64. </div>
  65. </div>
  66. <div class="row mb-4">
  67. <label for="budgetValue" class="col-md-2 col-lg-3 col-xl-2 col-form-label">
  68. <div class="d-flex flex-nowrap">
  69. 預算限制 <span class="text-danger">*</span>
  70. </div>
  71. </label>
  72. <div class="col-md-10 col-lg-9 col-xl-10">
  73. <select class="form-select" id="budgetValue" name="budgetValue">
  74. <option selected>請選擇</option>
  75. <option value="一萬以內">一萬以內</option>
  76. <option value="一萬到五萬">一萬到五萬</option>
  77. <option value="五萬到十萬">五萬到十萬</option>
  78. <option value="無預算限制">無預算限制</option>
  79. </select>
  80. </div>
  81. </div>
  82. <div class="row mb-4">
  83. <label for="demandValue" class="col-md-2 col-lg-3 col-xl-2 col-form-label">
  84. <div class="d-flex flex-nowrap">
  85. 需求目的 <span class="text-danger">*</span>
  86. </div>
  87. </label>
  88. <div class="col-md-10 col-lg-9 col-xl-10">
  89. <!-- <input type="text" class="form-control" id="demandValue" placeholder="請留下需求目的"> -->
  90. <fieldset>
  91. <div>
  92. <input type="radio" id="aiHost" name="demandValue" value="AI主持人" />
  93. <label for="aiHost">AI主持人(尾牙、活動)</label>
  94. <br>
  95. <input type="radio" id="aiGuide" name="demandValue" value="AI導覽員" />
  96. <label for="aiGuide">AI導覽員</label>
  97. <br>
  98. <input type="radio" id="aiOfficial" name="demandValue" value="AI長官替身" />
  99. <label for="aiOfficial">AI長官替身</label>
  100. <br>
  101. <input type="radio" id="otherOption" name="demandValue" value="其他" />
  102. <label for="otherOption">其他(可自行填寫)</label>
  103. <input type="text" id="otherText" class="w-100" style="border:1px solid #ced4da; border-radius: 3px;" />
  104. </div>
  105. </fieldset>
  106. </div>
  107. </div>
  108. <div class="row mb-4">
  109. <label for="captionValue" class="col-md-2 col-lg-3 col-xl-2 col-form-label">
  110. <div class="d-flex flex-nowrap">
  111. 需求說明 <span class="text-danger">*</span>
  112. </div>
  113. </label>
  114. <div class="col-md-10 col-lg-9 col-xl-10">
  115. <textarea class="form-control" id="captionValue" rows="3" placeholder="請簡述說明" required></textarea>
  116. </div>
  117. </div>
  118. <div class="row">
  119. <div class="col-md-10 col-lg-9 col-xl-10 offset-sm-2">
  120. <div class="form-check">
  121. <input class="form-check-input mt-2" type="checkbox" id="agreeValue">
  122. <label class="form-check-label w-100" for="agreeValue">
  123. 本人同意集仕多搜集資料
  124. </label>
  125. </div>
  126. </div>
  127. </div>
  128. <div style="height: 15px;">
  129. <span class="errorText text-danger">尚有欄位未填寫</span>
  130. </div>
  131. <div class="d-flex justify-content-center mt-5">
  132. <button type="submit" class="submit-btn" id="submitBtn">
  133. <span class="spinner-border spinner-border-sm me-2 loading-btn" role="status" aria-hidden="true"></span>
  134. 提交
  135. </button>
  136. </div>
  137. </form>
  138. </div>
  139. <script src="//code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  140. crossorigin="anonymous"></script>
  141. <!-- <script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
  142. <script type="module">
  143. import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
  144. const supabase = createClient('http://172.105.241.163:8000', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q');
  145. let { data: ai_news, error } = await supabase
  146. .from('ai_news')
  147. .select('*')
  148. console.log('ai_news', ai_news);
  149. const newData = {
  150. name: 'New AI News',
  151. data: "",
  152. };
  153. let { data: insertedData, error: insertError } = await supabase
  154. .from('ai_news')
  155. .insert([newData]);
  156. </script> -->
  157. <script>
  158. // 電話國碼
  159. const countryCodes = [
  160. '+1', // 美國
  161. '+7', // 俄羅斯
  162. '+33', // 法國
  163. '+39', // 義大利
  164. '+44', // 英國
  165. '+46', // 瑞典
  166. '+47', // 挪威
  167. '+49', // 德國
  168. '+52', // 墨西哥
  169. '+60', // 馬來西亞
  170. '+61', // 澳大利亞
  171. '+62', // 印尼
  172. '+64', // 紐西蘭
  173. '+65', // 新加坡
  174. '+66', // 泰國
  175. '+81', // 日本
  176. '+82', // 南韓
  177. '+86', // 中國大陸
  178. '+91', // 印度
  179. '+353', // 愛爾蘭
  180. '+852', // 香港
  181. '+853', // 澳門
  182. '+886', // 台灣
  183. ];
  184. const countryCode = document.getElementById('countryCode');
  185. countryCodes.forEach(code => {
  186. const option = document.createElement('option');
  187. option.value = code;
  188. option.text = code;
  189. countryCode.appendChild(option);
  190. });
  191. // 串接 Google Sheets 表單:https://docs.google.com/spreadsheets/d/1fvCmsUu-0lAraKMSbApUy8cQre3F85eQzzZyh9qwNzA/edit#gid=0
  192. $('.errorText').hide();
  193. $('.loading-btn').hide();
  194. const scriptURL = 'https://script.google.com/macros/s/AKfycbyAUKo8onoxuEgXP876QsR6q0_8379v4hMCvYVCk3gVaaTEIuK7hPNnOSKNWHlBJ4mVgA/exec';
  195. function send() {
  196. console.log('addEventListener');
  197. let name = document.querySelector('#nameValue').value; // 聯絡人
  198. let phone; // 聯絡電話
  199. let company = document.querySelector('#companyValue').value; // 公司名稱
  200. let email = document.querySelector('#emailValue').value; // 電子信箱
  201. let demand; // 需求目的
  202. let caption = document.querySelector('#captionValue').value; // 需求說明
  203. let budget = document.querySelector('#budgetValue').value; // 預算限制
  204. // let date = document.querySelector('#dateValue').value; // 預計活動需求日
  205. let agree; // 搜集資料
  206. let time; // 填單時間
  207. // 取得當下時間
  208. const now = new Date();
  209. const options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' };
  210. time = now.toLocaleString('zh-TW', options);
  211. console.log('time', time);
  212. if (document.querySelector('input[id="agreeValue"]:checked')) {
  213. agree = "同意";
  214. } else {
  215. agree = "不同意";
  216. }
  217. if (document.querySelector('input[name="demandValue"]:checked')) {
  218. demand = document.querySelector('input[name="demandValue"]:checked').value;
  219. }
  220. if (demand === "其他") {
  221. demand = document.querySelector('#otherText').value;
  222. }
  223. let countryCode = document.querySelector('#countryCode').value; // 國碼
  224. let phoneCode = document.querySelector('#phoneCode').value; // 電話號碼
  225. phone = `${countryCode} ${phoneCode}`;
  226. $.ajax({
  227. url: scriptURL,
  228. method: "post",
  229. data: {
  230. "name": name,
  231. "phone": phone,
  232. "company": company,
  233. "email": email,
  234. "demand": demand,
  235. "caption": caption,
  236. "budget": budget,
  237. // "date": date,
  238. "agree": agree,
  239. "time": time
  240. },
  241. success: function (response) {
  242. if (response == "成功") {
  243. $('.loading-btn').hide();
  244. alert("成功提交!");
  245. }
  246. },
  247. });
  248. // 寄信
  249. let templateParams = {
  250. name: name,
  251. phone: phone,
  252. company: company,
  253. email: email,
  254. demand: demand,
  255. caption: caption,
  256. budget: budget,
  257. date: date,
  258. agree: agree,
  259. };
  260. emailjs.send('service_kyazqjp', 'template_n0sqgwh', templateParams).then(
  261. (response) => {
  262. console.log('SUCCESS!', response.status, response.text);
  263. },
  264. (error) => {
  265. console.log('FAILED...', error);
  266. },
  267. );
  268. };
  269. $('button').on('click', function (e) {
  270. e.preventDefault();
  271. let countryCode = document.querySelector('#countryCode').value;
  272. let budget = document.querySelector('#budgetValue').value; // 預算限制
  273. let demand = ""; // 需求目的
  274. if (document.querySelector('input[name="demandValue"]:checked')) {
  275. demand = document.querySelector('input[name="demandValue"]:checked').value;
  276. }
  277. if (demand === "其他") {
  278. demand = document.querySelector('#otherText').value;
  279. }
  280. // 手動觸發表單提交
  281. let form = $(this).closest('form');
  282. form[0].reportValidity(); // 顯示瀏覽器內建錯誤提示
  283. if (countryCode === "選擇國碼" || budget === "請選擇" || demand === "") {
  284. console.log('表單未通過驗證');
  285. $('.errorText').show();
  286. return;
  287. }
  288. if (form[0].reportValidity()) {
  289. $('.loading-btn').show();
  290. $('.errorText').hide();
  291. send();
  292. }
  293. });
  294. </script>