/** * WP_メンバー登録フォーム */ class WpMemberRegistJsForm { /** * コンストラクタ */ constructor() { /** ユーザID */ this.member_id = ""; /** 氏名 */ this.member_name = ""; /** 氏名(カナ) */ this.member_name_kana = ""; /** 性別 */ this.gender = ""; /** 生年月日 */ this.date_of_birth = ""; /** メールアドレス */ this.mail_address = ""; /** メールアドレス(確認用) */ this.mail_address_confirm = ""; /** パスワード */ this.password = ""; /** パスワード(確認用) */ this.password_confirm = ""; /** 電話番号 */ this.tel_number = ""; /** 活動ジャンル */ this.act_kind = ""; /** お知らせメール */ this.is_send_mail = ""; /** 削除フラグ */ this.delete_flag = ""; /** 登録日時 */ this.regist_date = ""; /** 更新日時 */ this.update_date = ""; // コントロールクリア this.setControlStyle("member_name", "border: 1px solid #ccc;"); this.setControlStyle("member_name_kana", "border: 1px solid #ccc;"); this.setControlStyle("gender", "border: 1px solid #ccc;"); this.setControlStyle("date_of_birth", "border: 1px solid #ccc;"); this.setControlStyle("mail_address", "border: 1px solid #ccc;"); this.setControlStyle("mail_address_confirm", "border: 1px solid #ccc;"); this.setControlStyle("password", "border: 1px solid #ccc;"); this.setControlStyle("password_confirm", "border: 1px solid #ccc;"); this.setControlStyle("tel_number", "border: 1px solid #ccc;"); this.setControlStyle("act_kind", "border: 1px solid #ccc;"); this.setControlStyle("is_send_mail", "border: 1px solid #ccc;"); } /** * フォームデータを設定 */ setFormData() { var elm_member_name = document.getElementById('vol_form').member_name; if (elm_member_name != null) { this.member_name = elm_member_name.value; } var elm_member_name_kana = document.getElementById('vol_form').member_name_kana; if (elm_member_name_kana != null) { this.member_name_kana = elm_member_name_kana.value; } var elm_gender = document.getElementById('vol_form').gender; if (elm_gender != null) { this.gender = elm_gender.value; } var elm_date_of_birth = document.getElementById('vol_form').date_of_birth; if (elm_date_of_birth != null) { this.date_of_birth = elm_date_of_birth.value; } var elm_mail_address = document.getElementById('vol_form').mail_address; if (elm_mail_address != null) { this.mail_address = elm_mail_address.value; } var elm_mail_address_confirm = document.getElementById('vol_form').mail_address_confirm; if (elm_mail_address_confirm != null) { this.mail_address_confirm = elm_mail_address_confirm.value; } var elm_password = document.getElementById('vol_form').password; if (elm_password != null) { this.password = elm_password.value; } var elm_password_confirm = document.getElementById('vol_form').password_confirm; if (elm_password_confirm != null) { this.password_confirm = elm_password_confirm.value; } var elm_tel_number = document.getElementById('vol_form').tel_number; if (elm_tel_number != null) { this.tel_number = elm_tel_number.value; } const chkActKind = document.querySelectorAll('input[name="act_kind[]"]:checked'); const selectedValueActKind = Array.from(chkActKind).map(checkbox => checkbox.value); this.act_kind = selectedValueActKind; var elm_is_send_mail = document.getElementById('vol_form').is_send_mail; if (elm_is_send_mail != null) { this.is_send_mail = elm_is_send_mail.value; } } /** * バリデーション */ validate() { let errInfo = []; // 必須チェック if (this.member_name == "") { errInfo.push(["member_name", "氏名を入力してください。"]); } if (this.member_name_kana == "") { errInfo.push(["member_name_kana", "氏名(カナ)を入力してください。"]); } if (this.date_of_birth == "") { errInfo.push(["date_of_birth", "生年月日を入力してください。"]); } if (this.mail_address == "") { errInfo.push(["mail_address", "メールアドレスを入力してください。"]); } if (this.mail_address_confirm == "") { errInfo.push(["mail_address_confirm", "メールアドレス(確認用)を入力してください。"]); } if (this.password == "") { errInfo.push(["password", "パスワードを入力してください。"]); } if (this.password_confirm == "") { errInfo.push(["password_confirm", "パスワード(確認用)を入力してください。"]); } if (this.act_kind == "") { errInfo.push(["act_kind", "活動ジャンルを入力してください。"]); } if (this.is_send_mail == "") { errInfo.push(["is_send_mail", "お知らせメールを入力してください。"]); } // 桁数チェック if (errInfo.length == 0) { if (this.member_id.length > 32) { errInfo.push(["member_id", "ユーザIDの文字数が大きすぎます。"]); } if (this.member_name.length > 64) { errInfo.push(["member_name", "氏名の文字数が大きすぎます。"]); } if (this.member_name_kana.length > 64) { errInfo.push(["member_name_kana", "氏名(カナ)の文字数が大きすぎます。"]); } if (this.gender.length > 3) { errInfo.push(["gender", "性別の文字数が大きすぎます。"]); } if (this.date_of_birth.length > 12) { errInfo.push(["date_of_birth", "生年月日の文字数が大きすぎます。"]); } if (this.mail_address.length > 256) { errInfo.push(["mail_address", "メールアドレスの文字数が大きすぎます。"]); } if (this.mail_address_confirm.length > 256) { errInfo.push(["mail_address_confirm", "メールアドレス(確認用)の文字数が大きすぎます。"]); } if (this.password.length > 32) { errInfo.push(["password", "パスワードの文字数が大きすぎます。"]); } if (this.password_confirm.length > 32) { errInfo.push(["password_confirm", "パスワード(確認用)の文字数が大きすぎます。"]); } if (this.password.length < 8) { errInfo.push(["password", "パスワードは英数8文字以上で入力してください。"]); } if (this.password_confirm.length < 8) { errInfo.push(["password_confirm", "パスワード(確認用)は英数8文字以上で入力してください。"]); } if (this.tel_number.length > 20) { errInfo.push(["tel_number", "電話番号の文字数が大きすぎます。"]); } if (this.act_kind.length > 64) { errInfo.push(["act_kind", "活動ジャンルの文字数が大きすぎます。"]); } if (this.is_send_mail.length > 1) { errInfo.push(["is_send_mail", "お知らせメールの文字数が大きすぎます。"]); } } // 入力形式チェック if (errInfo.length == 0) { if (validString(this.member_name) != true) { errInfo.push(["member_name", "氏名の入力形式が正しくありません。"]); } if (validZenkakuKana(this.member_name_kana) != true) { errInfo.push(["member_name_kana", "氏名(カナ)の入力形式が正しくありません。"]); } if (validDate(this.date_of_birth) != true) { errInfo.push(["date_of_birth", "生年月日の入力形式が正しくありません。"]); } if (validMailAddress(this.mail_address) != true) { errInfo.push(["mail_address", "メールアドレスの入力形式が正しくありません。"]); } if (validMailAddress(this.mail_address_confirm) != true) { errInfo.push(["mail_address_confirm", "メールアドレス(確認用)の入力形式が正しくありません。"]); } if (validPasswd(this.password) != true) { errInfo.push(["password", "パスワードの入力形式が正しくありません。"]); } if (validPasswd(this.password_confirm) != true) { errInfo.push(["password_confirm", "パスワード(確認用)の入力形式が正しくありません。"]); } const pw = this.password; if (!/[A-Za-z]/.test(pw) || !/[0-9]/.test(pw)) { errInfo.push(["password", "パスワードには英字と数字を両方含めてください。"]); } if (validTel(this.tel_number) != true) { errInfo.push(["tel_number", "電話番号の入力形式が正しくありません。"]); } } // 範囲チェック if (errInfo.length == 0) { var isErr_date_of_birth = false; if (this.date_of_birth < "1900-01-01") { isErr_date_of_birth = true; } if (this.date_of_birth > "2024-12-31") { isErr_date_of_birth = true; } if (isErr_date_of_birth == true) { errInfo.push(["date_of_birth", "生年月日の入力範囲が正しくありません。"]); } } // 相関チェック if (errInfo.length == 0) { var errMsg = eqMailAddress(this.mail_address, this.mail_address_confirm); if (errMsg != "") { errInfo.push(["mail_address", errMsg]); } var errMsg = eqPasswd(this.password, this.password_confirm); if (errMsg != "") { errInfo.push(["password", errMsg]); } } // エラー情報設定 errInfo.forEach(function (err) { this.setControlStyle(err[0], "border: 1px solid red;"); }, this); return errInfo; } /** * コントロールにスタイルを適用する */ setControlStyle(ctrlName, style) { let ctrls = document.getElementsByName(ctrlName); ctrls.forEach(function (ctrl) { ctrl.style = style; }); } }