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.

101 lines
4.0 KiB

2 years ago
  1. $(function () {
  2. 'use strict';
  3. var sLang = $('[http-equiv="content-language"]').attr('content') || 'zh-TW',
  4. bEn = sLang === 'en',
  5. eForm = $("#form_contact"),
  6. /*
  7. * 目的 表單驗證初始化
  8. */
  9. fnSetForm_Rule = function () {
  10. eForm.validate({
  11. errorPlacement: function (error, element) {
  12. error.css({
  13. "border": "none",
  14. "color": "red"
  15. });
  16. var wrapper = $("<p></p>");
  17. error.appendTo(wrapper);
  18. $(element).parent().after(wrapper);
  19. },
  20. highlight: function (element, errorClass) {
  21. $(element).css({
  22. "border": "1px solid red"
  23. });
  24. },
  25. unhighlight: function (element, errorClass) {
  26. $(element).css({
  27. "border": ""
  28. });
  29. },
  30. rules: {
  31. },
  32. messages: {
  33. uname: {
  34. required: bEn ? 'Please enter contact name' : "請輸入聯絡人姓名"
  35. },
  36. uemail: {
  37. email: bEn ? 'Wrong email format' : "電子信箱格式錯誤",
  38. required: bEn ? 'Please enter your email address' : "請輸入電子信箱"
  39. },
  40. ucomp: {
  41. required: bEn ? 'Please enter the company name' : "請輸入公司名稱"
  42. },
  43. utel: {
  44. required: bEn ? 'Please enter your contact number' : "請輸入聯絡電話"
  45. },
  46. umailcontent: {
  47. required: bEn ? 'Please enter the content' : "請輸入內容"
  48. },
  49. validcode: {
  50. required: bEn ? 'Please enter the verification code' : "請輸入驗證碼"
  51. }
  52. }
  53. });
  54. },
  55. /*
  56. * 目的 寄送郵件
  57. */
  58. fnSendMail = function () {
  59. if (!eForm.valid()) {
  60. return false;
  61. }
  62. var formdata = getFormSerialize(eForm);
  63. formdata.flag = 'cap2';
  64. formdata.type = 'C';
  65. return g_api.ConnectLite(Service.apiwebcom, 'SendMail', formdata, function (res) {
  66. if (res.RESULT) {
  67. if (res.DATA.rel) {
  68. showMsg(bEn ? 'The mail has been sent out and we will deal with it for you as soon as possible' : '郵件已經寄出,我們將儘快為您處理', 'success'); // 郵件已經寄出,我們將儘快為您處理。
  69. setTimeout(function () {
  70. location.reload();
  71. }, 3000);
  72. }
  73. else {
  74. showMsg(bEn ? 'Please enter contact name' : '郵件寄送失敗', 'error'); // 郵件寄送失敗
  75. $('#change_validcode').click();
  76. }
  77. }
  78. else {
  79. showMsg(res.MSG, 'error'); // 驗證碼錯誤
  80. $('#change_validcode').click();
  81. }
  82. }, function () {
  83. showMsg(bEn ? 'Mail delivery failed' : '郵件寄送失敗', 'error'); // 郵件寄送失敗
  84. }, null, bEn ? 'In the mail...' : '郵件寄送中...');
  85. },
  86. init = function () {
  87. $('#change_validcode,.change_validcode').on('click', function () {
  88. var url = $('#imgvalidcode').data('url') || $('#imgvalidcode').attr('src');
  89. $('#imgvalidcode').attr('src', url + '&' + Math.random()).data('url', url);
  90. });
  91. fnSetForm_Rule();
  92. $("#sendmail").on("click", function () {
  93. fnSendMail();
  94. });
  95. };
  96. init();
  97. });