// メール送信 // [form dialog.error]と[form dialog.success]のスタイルが必要 $.fn.sendmail = function(title){ var $form = this, action = $form.attr('action'), method = $form.attr('method'), delimiter = ','; $form.on({ submit: function(){ var dat = {}, errors = [], message = ''; // データ取得[name, value, field, required] $.each($form.serializeArray(), function(i, item){ if($.type(dat[item.name]) === 'undefined') dat[item.name] = []; $.extend(item, { field: $.type($form.find('[name="' + item.name + '"]').attr('data-field')) === 'undefined' ? '' : $form.find('[name="' + item.name + '"]').attr('data-field'), required: $.type($form.find('[name="' + item.name + '"]').attr('required')) === 'undefined' ? false : true }); if(item.required && (item.value === false || item.value === '')) errors.push(item.field + 'は必須項目です。'); dat[item.name].push(item); }); // 複数項目をデリミタで集約 $.each(dat, function(i, item){ if(item.length > 1){ var values = [], host = dat[i][0]; $.each(item, function(){ values.push(this.value); }); host.value = values.join(delimiter); dat[i] = host; } else { dat[i] = dat[i][0]; } }); // メールアドレスチェック $form.find('[name]').filter('[type="email"]').each(function(){ if(!$(this).val().match(/^[A-Za-z0-9]+[\w-]+@[\w\.-]+\.\w{2,}$/)) errors.push($(this).data('field') + 'の書式が正しくありません。'); }); // 本文作成 $.each(dat, function(i, item){ message += item.field + ':' + item.value + "\n"; }); // エラー出力初期化 $form.children('dialog').remove(); // ダイアログ作成 dialog.関数名(タイトル, 通知文, 0[OK]か1[OK/CANCEL]) var dialog = { makeinterface: function(iflg){ var $interface = $(); switch(iflg){ case 1: $interface = $('