Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('#donateForm').submit(function (e) {
- var ok = true;
- var $go = undefined;
- var check = {
- 'anonymous': {
- 'anonymous_email': {
- 'checkFunction': function (text) {
- if ($('#anonymous_event:checked').length) {
- return /^.+@.+\..{2,3}$/.test(text);
- } else {
- return true;
- }
- }
- },
- 'notice': {
- 'msg': '您必須閱讀並勾選此項目',
- 'checkFunction': function (text) {
- return !!$('#notice:checked').length;
- }
- },
- 'amount': {
- 'msg': '請先選擇捐款方式',
- 'checkFunction': function (text) {
- var method = $('input[name=method]:checked').val();
- if (!method) {
- return false;
- }
- this.msg = '金額必須為介於 100 至 10000 的正整數';
- if (!/^\d+$/.test(text)) {
- return false;
- }
- if (parseInt(text) < 100 || parseInt(text) > 10000) {
- return false;
- }
- return true;
- }
- }
- },
- 'onymous': {
- 'name': {
- 'msg': '欄位不得為空',
- 'checkFunction': function (text) {
- return !!text.length;
- }
- },
- 'idn': {
- 'msg': '格式錯誤,範例:A123456789',
- 'checkFunction': function (id) {
- var tab = "ABCDEFGHJKLMNPQRSTUVXYWZIO";
- var A1 = new Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3);
- var A2 = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5);
- var Mx = new Array(9, 8, 7, 6, 5, 4, 3, 2, 1, 1);
- if (!/^[A-Z][1-2]\d{8,8}$/i.test(id)) {
- return false;
- }
- var i = tab.indexOf(id.charAt(0));
- var sum = A1[i] + A2[i] * 9;
- for (var j = 1; j <= 9; j++) {
- var v = parseInt(id.charAt(j));
- sum += v * Mx[j];
- }
- if (sum % 10) {
- return false;
- }
- return true;
- }
- },
- 'mobile': {
- 'msg': '格式錯誤,範例:0987654321',
- 'checkFunction': function (text) {
- return /^09\d{8,8}$/.test(text);
- }
- },
- 'tel': {
- 'msg': '欄位不得為空',
- 'checkFunction': function (text) {
- return !!text.length;
- }
- },
- 'email': {
- 'checkFunction': function (text) {
- return /^.+@.+\..{2,3}$/.test(text);
- }
- },
- 'zipcode': {
- 'msg': '格式錯誤,範例:12345',
- 'checkFunction': function (text) {
- return /^\d{5,5}$/.test(text);
- }
- },
- 'address': {
- 'msg': '欄位不得為空',
- 'checkFunction': function (text) {
- return !!text.length;
- }
- },
- 'receipt': {
- 'msg': '欄位不得為空',
- 'checkFunction': function (text) {
- if (!text.length) return false;
- if (!(text.indexOf("號") >= 0)) {
- this.msg = '請輸入正確地址';
- return false;
- }
- return true;
- }
- },
- 'notice': {
- 'msg': '您必須閱讀並勾選此項目',
- 'checkFunction': function (text) {
- return !!$('#notice:checked').length;
- }
- },
- 'amount': {
- 'msg': '請先選擇捐款方式',
- 'checkFunction': function (text) {
- var method = $('input[name=method]:checked').val();
- var methodLimit = {
- 1: 30000,
- 2: 30000,
- 4: 30000,
- 8: 20000,
- 9: 20000,
- 11: 100000,
- 12: 20000
- };
- if (!method) {
- return false;
- }
- this.msg = '金額必須為介於 100 至 ' + methodLimit[method] + ' 的正整數';
- if (!/^\d+$/.test(text)) {
- return false;
- }
- if (parseInt(text) < 100 || parseInt(text) > methodLimit[method]) {
- return false;
- }
- return true;
- }
- }
- }
- };
- var checkObj = isAnonymous() ? check.anonymous : check.onymous;
- $(this).find('.error').remove();
- $.each(checkObj, function (index, value) {
- var $obj = $('input[name=' + index + ']');
- if (!value.checkFunction.call(this, $obj.val())) {
- appendErrorMsg($obj.parent(), value.msg);
- ok = false;
- if (!$go) {
- $go = $obj.parents('.box');
- }
- }
- });
- if (!ok) {
- var $page = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html, body');
- $page.stop(true, true).animate({scrollTop: $go.offset().top - 10}, 500);
- return e.preventDefault();
- }
- $.ajax({
- url: './index.php?i=donation&action=pay'.replace(/&/ig, '&'),
- type: 'POST',
- dataType: 'HTML',
- data: $('#donateForm').serializeArray(),
- beforeSend: function () {
- $('#submit').prop('disabled', true);
- },
- success: function (data) {
- $('<form>')
- .attr({
- 'action': 'https://www.twv.com.tw/openpay/pay.php'.replace(/&/ig, '&'),
- 'method': 'POST'
- })
- .append($(data).find('#pay'))
- .hide()
- .appendTo('body')
- .submit();
- }
- });
- return e.preventDefault();
- });
Advertisement
Add Comment
Please, Sign In to add comment