$(function(){ $(window).on('load',function(){ if($(window).width() <= 768){ var foot_height = $('.foot_tel').innerHeight(); $('footer ul').css('margin-bottom',foot_height); } }); $('#inputform').submit(function(e) { if(validate($(this))){ closeblock($(this)); return false; }else{ return false; } }); $(document).on('change', 'select[name="prefecture"]', function(e) { $('select[name="city"] option').remove(); $('select[name="city"]').append($('選択して下さい')); Object.keys(city_array[$(this).val()]).forEach(function (key){ $('select[name="city"]').append($('').html(key).val(key)); }); }); $(".place .item h3").on("click", function () { $(this).parent().find('.value').toggle(500); $(this).toggleClass('on'); }); $(".question .item h3").on("click", function () { $(this).parent().find('p').toggle(500); $(this).toggleClass('on'); }); $('input[name="photo"]').on('change', function() { $('.photo_value').remove(); $('.inputphoto').remove(); $(this).parent('label').after(''+$(this).prop('files')[0].name+''); }); }); function validate(thisdata){ $('.error_val').remove(); var error_chk = 0; if(!$('select[name="place"] option:selected').val()){ // $('input[name="place_etc"]').after('場所は一つ以上選択してください'); $('select[name="place"]').after('場所は一つ以上選択してください'); error_chk = 1; // }else if($('.place_etc').prop('checked') && !$('input[name="place_etc"]').val()){ // $('input[name="place_etc"]').after('その他の詳細を入力してください'); // error_chk = 1; } if(!$('select[name="incident"] option:selected').val()){ // $('input[name="incident_etc"]').after('お困りの事象は一つ以上選択してください'); $('select[name="incident"]').after('お困りの事象は一つ以上選択してください'); error_chk = 1; // }else if($('.incident_etc').prop('checked') && !$('input[name="incident_etc"]').val()){ // $('input[name="incident_etc"]').after('その他の詳細を入力してください'); // error_chk = 1; } // if(!$('input[name="_name"]').val()){ // $('input[name="_name"]').after('名前は必須項目です'); // error_chk = 1; // } // if(!$('input[name="_furi"]').val()){ // $('input[name="_furi"]').after('フリガナは必須項目です'); // error_chk = 1; // } // if(!$('input[name="_email"]').val()){ // $('input[name="_email"]').after('メールアドレスは必須項目です'); // error_chk = 1; // } // if($('input[name="_email"]').val() != $('input[name="_email_chk"]').val()){ // $('input[name="_email_chk"]').after('メールアドレスが確認用と一致しません'); // error_chk = 1; // } var telval = $('input[name="_tel"]').val(); telval = telval.replace(/━|‐|―|-|\-|ー|\-/g,''); if(!$('input[name="_tel"]').val()){ $('input[name="_tel"]').after('電話番号は必須項目です'); error_chk = 1; }else if(!telval.match(/^\d{11}$/)){ $('input[name="_tel"]').after('電話番号は半角数字で入力してください'); error_chk = 1; } if(!$('input[name="_zip"]').val()){ $('input[name="_zip"]').after('郵便番号は必須項目です'); error_chk = 1; } if(!$('select[name="land"] option:selected').val()){ $('select[name="land"]').after('都道府県は必須項目です'); error_chk = 1; } if(!$('input[name="_city"]').val()){ $('input[name="_city"]').after('市区町村は必須項目です'); error_chk = 1; } // if(!$('input[name="_banti"]').val()){ // $('input[name="_banti"]').after('丁目・番地は必須項目です'); // error_chk = 1; // } // if(!$('input[name="emergency"]:checked').val()){ // $('input[name="emergency_etc"]').after('お問い合わせの緊急度は必須項目です'); // error_chk = 1; // }else if($('.emergency_etc').prop('checked') && !$('input[name="emergency_etc"]').val()){ // $('input[name="emergency_etc"]').after('その他の詳細を入力してください'); // error_chk = 1; // } // if(!$('select[name="hour"] option:selected').val()){ // $('select[name="hour"]').after('ご連絡可能な時間帯は必須項目です'); // error_chk = 1; // } if(!$('input[name="agree"]:checked').val()){ $('input[name="agree"]').parent('label').after('個人情報の取り扱いに同意してください'); error_chk = 1; } if(error_chk){ alert('入力内容に不備がありますので、各項目を確認してください。'); $(window).scrollTop($('#form').position().top); return false; }else{ return true; } } function closeblock(thisdata){ var data = { 'entry_id': $('#inputform input[name="entry_id"]').val(), 'place': $('#inputform select[name="place"] option:selected').val(), 'place_etc': $('#inputform input[name="place_etc"]').val(), 'incident': $('#inputform select[name="incident"] option:selected').val(), 'incident_etc': $('#inputform input[name="incident_etc"]').val(), '_name': $('#inputform input[name="_name"]').val(), '_furi': $('#inputform input[name="_furi"]').val(), '_email': $('#inputform input[name="_email"]').val(), '_email_chk': $('#inputform input[name="_email_chk"]').val(), '_tel': $('#inputform input[name="_tel"]').val(), '_zip': $('#inputform input[name="_zip"]').val(), 'land': $('#inputform select[name="land"] option:selected').val(), '_city': $('#inputform input[name="_city"]').val(), '_banti': $('#inputform input[name="_banti"]').val(), '_building': $('#inputform input[name="_building"]').val(), 'emergency': $('#inputform input[name="emergency"]').val(), 'emergency_etc': $('#inputform input[name="emergency_etc"]').val(), 'hour': $('#inputform input[name="hour"]').val(), 'etc': $('#inputform input[name="etc"]').val(), 'agree': $('#inputform input[name="agree"]').val(), 'photoname': $('#inputform input[name="photoname"]').val(), 'contact_distinct_comp': $('#inputform input[name="contact_distinct_comp"]').val(), 'contact_distinct_affi': $('#inputform input[name="contact_distinct_affi"]').val() } $.ajax({ url: '/leg/water/suido/php/send_contact_mail.php', data: data, type: 'POST', timeout: 50000, }).done(function(data) { if(data.data.error){ alert(data.data.message); }else{ location.href = '/leg/water/suido/thanks.html?entry_id=' + data.data.entry_id + '&af=' + $('#inputform input[name="af"]').val(); } }).fail(function(errors) { }) }