質問編集履歴

3

不要な部分を除去

2016/11/16 08:04

投稿

hidepon
hidepon

スコア206

test CHANGED
File without changes
test CHANGED
@@ -116,12 +116,6 @@
116
116
 
117
117
  $post_array = $this->input->post();
118
118
 
119
- //カテゴリー
120
-
121
- $category_array = $this->category->Get_Parent_Category();
122
-
123
- $data["category_str"] = $this->common->Create_Category_List($category_array);
124
-
125
119
  //検証ルール
126
120
 
127
121
  $this->form_validation->set_rules('email','メールアドレス',array('required','min_length[10]','max_length[128]','matches[email_conf]','callback_check_duplicate_email'));

2

登録内容の誤記

2016/11/16 08:04

投稿

hidepon
hidepon

スコア206

test CHANGED
File without changes
test CHANGED
@@ -124,9 +124,9 @@
124
124
 
125
125
  //検証ルール
126
126
 
127
- $this->form_validation->set_rules('email','メールアドレス',array('required','min_length[10]','max_length[128]','matches[email_address_conf]','callback_check_duplicate_email'));
127
+ $this->form_validation->set_rules('email','メールアドレス',array('required','min_length[10]','max_length[128]','matches[email_conf]','callback_check_duplicate_email'));
128
128
 
129
- $this->form_validation->set_rules('email_conf','メールアドレス(確認)',array('required','min_length[10]','max_length[128]','matches[email_address_conf]'));
129
+ $this->form_validation->set_rules('email_conf','メールアドレス(確認)',array('required','min_length[10]','max_length[128]'));
130
130
 
131
131
  //入力チェック
132
132
 

1

該当部分のみを抜粋して再登録します

2016/11/16 06:25

投稿

hidepon
hidepon

スコア206

test CHANGED
@@ -1 +1 @@
1
- Codeigniter3.Xでの入力チェックで特定の項目だけがエラーに
1
+ Codeigniter3.Xでメールアドレスの入力チェック
test CHANGED
@@ -1,140 +1,14 @@
1
1
  CodeIgniterで開発を行っています。
2
2
 
3
- 入力チェックでemail とpasswordの項目のチェックだけがほかの項目と異なる挙動を示しています。
3
+ 入力チェックでemail がほかの項目と異なる挙動を示しています。
4
+
5
+ (下記はemailのみ抜粋)
4
6
 
5
7
  ```
6
8
 
7
9
  <table class="table" id="tbl_member">
8
10
 
9
11
  <tbody>
10
-
11
- <tr>
12
-
13
- <th>お名前<span class="aster">※</span></th>
14
-
15
- <td><input type="text" name="name1" id="name1" />&nbsp;<input type="text" name="name2" id="name2" /></td>
16
-
17
- </tr>
18
-
19
- <tr>
20
-
21
- <th>フリガナ<span class="aster">※</span></th>
22
-
23
- <td><input type="text" name="name_kana1" id="name_kana1" />&nbsp;<input type="text" name="name_kana2" id="name_kana2" /></td>
24
-
25
- </tr>
26
-
27
- <tr>
28
-
29
- <th>性別<span class="aster">※</span></th>
30
-
31
- <td><input type="radio" name="sex" value="1" id="sex1" checked="checked" />男性<input type="radio" name="sex" value="2" id="sex2" />女性</td>
32
-
33
- </tr>
34
-
35
- <tr>
36
-
37
- <th>郵便番号<span class="aster">※</span></th>
38
-
39
- <td><input type="text" name="zip" id="zip" size="6" maxlength="7" /><input type="button" name="addr_search_member" id="addr_search_member" value="住所検索" class="modal_btn" /></td>
40
-
41
- </tr>
42
-
43
- <tr>
44
-
45
- <th>都道府県<span class="aster">※</span></th>
46
-
47
- <td>
48
-
49
- <select name="prefecture" id="prefecture">
50
-
51
- <option value ="01" selected="selected">北海道</option> <option value ="02">青森県</option>
52
-
53
- (割愛します)
54
-
55
- </select>
56
-
57
- </td>
58
-
59
- </tr>
60
-
61
- <tr>
62
-
63
- <th>市区町村名<span class="aster">※</span></th>
64
-
65
- <td><input type="text" name="address1" id="address1" size="50" /></td>
66
-
67
- </tr>
68
-
69
- <tr>
70
-
71
- <th>番地・建物名<span class="aster">※</span></th>
72
-
73
- <td><input type="text" name="address2" id="address2" size="50" /></td>
74
-
75
- </tr>
76
-
77
- <tr>
78
-
79
- <th>電話番号<span class="aster">※</span></th>
80
-
81
- <td><input type="text" name="tel" id="tel" /></td>
82
-
83
- </tr>
84
-
85
- <tr>
86
-
87
- <th>携帯電話番号</th>
88
-
89
- <td><input type="text" name="mobtel" id="mobtel" /></td>
90
-
91
- </tr>
92
-
93
- <tr>
94
-
95
- <th>生年月日<span class="aster">※</span></th>
96
-
97
- <td>
98
-
99
- <select name="birth_year" id="birth_year">
100
-
101
- <option value ="1931">1931</option>
102
-
103
- <option value ="1932">1932</option>
104
-
105
- (割愛します)
106
-
107
- </select>
108
-
109
-
110
-
111
- <select name="birth_month" id="birth_month">
112
-
113
- <option value ="1">1</option>
114
-
115
- <option value ="2">2</option>
116
-
117
- (割愛します)
118
-
119
- </select>
120
-
121
-
122
-
123
- <select name="birth_day" id="birth_day">
124
-
125
- <option value ="1">1</option>
126
-
127
- <option value ="2">2</option>
128
-
129
- (割愛します)
130
-
131
- </select>
132
-
133
-
134
-
135
- </td>
136
-
137
- </tr>
138
12
 
139
13
  <tr>
140
14
 
@@ -152,30 +26,6 @@
152
26
 
153
27
  </tr>
154
28
 
155
- <tr>
156
-
157
- <th>パスワード<span class="aster">※</span></th>
158
-
159
- <td><input type="password" name="password" id="password" /></td>
160
-
161
- </tr>
162
-
163
- <tr>
164
-
165
- <th>パスワード(確認)<span class="aster">※</span></th>
166
-
167
- <td><input type="password" name="password_conf" id="password_conf" /></td>
168
-
169
- </tr>
170
-
171
- <tr>
172
-
173
- <th>情報メールの受信<span class="aster">※</span></th>
174
-
175
- <td><input type="radio" name="optin" value="1" id="optin1" />受信する<input type="radio" name="optin" value="2" id="optin2" checked="checked" />受信しない</td>
176
-
177
- </tr>
178
-
179
29
  </tbody>
180
30
 
181
31
  </table>
@@ -188,47 +38,149 @@
188
38
 
189
39
  ```
190
40
 
191
- //検証ルール
41
+ public function index(){
192
42
 
193
- $this->form_validation->set_rules('name1','名前(姓)','required|min_length[1]|max_length[10]');
43
+ //SESSIONデータ
194
44
 
195
- $this->form_validation->set_rules('name2','名前(名)','required|min_length[1]|max_length[10]');
45
+ $session_array = array();
196
46
 
197
- $this->form_validation->set_rules('name_kana1','名前カナ(姓)','required|min_length[1]|max_length[20]');
47
+ $session_array = $this->session->all_userdata();
198
48
 
199
- $this->form_validation->set_rules('name_kana2','名前カナ(名)','required|min_length[1]|max_length[20]');
49
+ //POSTデータ
200
50
 
201
- $this->form_validation->set_rules('sex','性別','required|exact_length[1]|alpha_numeric');
51
+ $post_array = array();
202
52
 
203
- $this->form_validation->set_rules('email','メールアドレス','required|min_length[10]|max_length[128]|matches[email_conf]|callback_check_duplicate_email');
53
+ $post_array = $this->input->post();
204
54
 
205
- $this->form_validation->set_rules('password','パスワード','required|min_length[4]|max_length[15]|matches[password_conf]');
55
+ $data = array();
206
56
 
207
- $this->form_validation->set_rules('address1','住所1','required|min_length[5]|max_length[50]');
57
+ //POSTデータが存在する
208
58
 
209
- $this->form_validation->set_rules('address2','住所2','min_length[3]|max_length[100]');
59
+ if(!empty($post_array)){
210
60
 
211
- $this->form_validation->set_rules('zip','郵便番号','required|exact_length[7]|alpha_numeric');
61
+ //入力チェック
212
62
 
213
- $this->form_validation->set_rules('tel','電話番号','required|min_length[10]|max_length[18]|alpha_numeric');
63
+ if($this->validation_check()){
214
64
 
215
- $this->form_validation->set_rules('mobtel','携帯電話','min_length[10]|max_length[128]|alpha_numeric');
65
+ $data = array_merge($data,$post_array);
216
66
 
217
- $this->form_validation->set_rules('birth_year','生年月日(年)','required|alpha_numeric|callback_birth_date_check');
67
+ $this->session->set_userdata($post_array);
218
68
 
219
- $this->form_validation->set_rules('birth_month','生年月日(月)','required|alpha_numeric');
69
+ $data["title"] = "会員情報(新規登録)";
220
70
 
71
+ //HeaderのVIEW
72
+
73
+ $this->load->view('/header/header_011',$data);
74
+
221
- $this->form_validation->set_rules('birth_day','生年月日(日)','required|alpha_numeric');
75
+ $this->load->view('/common/parts_not_login',$data);
76
+
77
+ $this->load->view('/member/confirm',$data);
78
+
79
+ $this->load->view('/common/parts_footer',$data);
80
+
81
+ }
82
+
83
+ }else{
84
+
85
+ $data["title"] = "会員情報(新規登録)";
86
+
87
+ //HeaderのVIEW
88
+
89
+ $this->load->view('/header/header_011',$data);
90
+
91
+ $this->load->view('/common/parts_not_login',$data);
92
+
93
+ $this->load->view('/member/input',$data);
94
+
95
+ $this->load->view('/common/parts_footer',$data);
96
+
97
+ }
98
+
99
+ }
222
100
 
223
101
 
224
102
 
103
+ //入力チェック
104
+
105
+ private function validation_check(){
106
+
107
+ //SESSIONデータ
108
+
109
+ $session_array = array();
110
+
111
+ $session_array = $this->session->all_userdata();
112
+
113
+ //POSTデータ
114
+
115
+ $post_array = array();
116
+
117
+ $post_array = $this->input->post();
118
+
119
+ //カテゴリー
120
+
121
+ $category_array = $this->category->Get_Parent_Category();
122
+
123
+ $data["category_str"] = $this->common->Create_Category_List($category_array);
124
+
125
+ //検証ルール
126
+
127
+ $this->form_validation->set_rules('email','メールアドレス',array('required','min_length[10]','max_length[128]','matches[email_address_conf]','callback_check_duplicate_email'));
128
+
129
+ $this->form_validation->set_rules('email_conf','メールアドレス(確認)',array('required','min_length[10]','max_length[128]','matches[email_address_conf]'));
130
+
131
+ //入力チェック
132
+
133
+ if($this->form_validation->run() == FALSE ){
134
+
135
+ $this->form_validation->set_error_delimiters('<span class="em">', '</span>');
136
+
137
+ //配列を結合する
138
+
139
+ $data = array_merge($post_array,$data);
140
+
141
+ $data["title"] = "会員情報(新規登録エラー)";
142
+
143
+ //HeaderのVIEW
144
+
145
+ $this->load->view('/header/header_011',$data);
146
+
147
+ $this->load->view('/common/parts_not_login',$data);
148
+
149
+ $this->load->view('/member/input_error',$data);
150
+
151
+ $this->load->view('/common/parts_footer',$data);
152
+
153
+ return FALSE;
154
+
155
+ }else{
156
+
157
+ return TRUE;
158
+
159
+ }
160
+
161
+ }
162
+
163
+
164
+
165
+ //重複確認
166
+
167
+ public function check_duplicate_email(){
168
+
169
+ if($this->duplicate_check->Check_Duplicate_Email()){
170
+
171
+ $this->form_validation->set_message("check_duplicate_email","この%s は、すでに利用されています。");
172
+
173
+ return FALSE;
174
+
175
+ }
176
+
177
+ }
178
+
225
179
  ```
226
180
 
227
- としているんですが、
181
+ としているんですが、入力を行っても
228
182
 
229
183
  emailが「メールアドレス欄は必須フィールドです。」
230
-
231
- password が「パスワード欄が password_conf欄と同じではありません」
232
184
 
233
185
  と表示されてしまいます。
234
186