-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.php
185 lines (157 loc) · 6.38 KB
/
form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
require_once('error_checker.php');
require_once('format_text.php');
require_once('select_box.php');
require_once('prefecture_data.php');
/*以下表示用*/
$HOBBYS = array('music' => '音楽鑑賞','movie' => '映画鑑賞','other' => 'その他');
$NAMES = array(
'name_first', 'name_last', 'sex', 'post_first', 'post_last',
'prefecture','mail_address', 'other_descript', 'opinion'
);
$formated_post = getFormatedTextArray($_POST);
$man_checked = (getPOST('sex', $formated_post) == "男性")? "checked" : "";
$woman_checked = (getPOST('sex', $formated_post) == "女性")? "checked" : "";
$check_list = getPOSTArray('hobby', $formated_post);
//値のエラーをチェックし、エラー一覧を返す
function checkErrors($post_data) {
//エラーチェックの引数リスト作成
$name_check_functions = array(
new Check_Function_Data('name_first', $post_data['name_first'], 'checkIsNoText', 0),
new Check_Function_Data('name_last', $post_data['name_last'] , 'checkIsNoText', 0),
new Check_Function_Data('name_first', $post_data['name_first'], 'checkIsOverText', 1, 50),
new Check_Function_Data('name_last', $post_data['name_last'] , 'checkIsOverText', 1, 50)
);
$name_checker = new Error_Checker(
'名前',
$name_check_functions
);
$sex_value = isset($post_data['sex']) ? $post_data['sex'] : '';
$sex_check_functions = array(
new Check_Function_Data('sex', $sex_value, 'checkIsNoChoise', 0)
);
$sex_checker = new Error_Checker(
'性別',
$sex_check_functions
);
$post_check_functions = array(
new Check_Function_Data('post_first', $post_data['post_first'], 'checkIsNoText', 0),
new Check_Function_Data('post_last', $post_data['post_last'], 'checkIsNoText', 1),
new Check_Function_Data('post_first', $post_data['post_first'], 'checkIsIllegal', 2),
new Check_Function_Data('post_last', $post_data['post_last'], 'checkIsIllegal', 3)
);
$post_checker = new Error_Checker(
'郵便番号',
$post_check_functions
);
$prefecture_check_functions = array(
new Check_Function_Data('prefecture', $post_data['prefecture'], 'checkIsEmptyValue', 0, '--')
);
$prefecture_checker = new Error_Checker(
'都道府県',
$prefecture_check_functions
);
$mail_address_check_functions = array(
new Check_Function_Data('mail_address', $post_data['mail_address'], 'checkIsNoText', 0),
new Check_Function_Data('mail_address', $post_data['mail_address'], 'checkIsIllegal', 1),
new Check_Function_Data('mail_address', $post_data['mail_address'], 'checkIsOverLap', 2)
);
$mail_address_checker = new Error_Checker(
'メールアドレス',
$mail_address_check_functions
);
$hobby_check_functions = array();
if (isset($post_data['hobby']) && in_array('その他', $post_data['hobby'])) {
$other_hobby_value = isset($post_data['other_descript']) ? $post_data['other_descript'] : '';
array_push(
$hobby_check_functions,
new Check_Function_Data('other_descript', $other_hobby_value, 'checkIsNoText', 0)
);
}
$hobby_checker = new Error_Checker(
'趣味',
$hobby_check_functions
);
$checkers = array(
$name_checker,
$sex_checker,
$post_checker,
$prefecture_checker,
$mail_address_checker,
$hobby_checker
);
//エラー一覧を取得
$errors = array();
foreach ($checkers as $checker) {
array_push($errors, $checker->getCheckResult());
}
return $errors;
}
//次のページに行けるならジャンプする関数。入力をform.phpに戻し、エラーがないならformCheck.phpへジャンプ
function checkJump($post_data) {
if (empty($post_data) || isset($post_data['return'])) return;
checkErrors($post_data);
if (Error_Message::hasError() == false ) {
print "onLoad='document.checkForm.submit();'";
}
}
//エラーがあればエラー一覧を表示
function showError($post_data) {
if (empty($post_data) || isset($post_data['return'])) return;
if (Error_Message::hasError()) {
$error_texts = Error_Message::getAllErrorString();
foreach ($error_texts as $error) {
printf("%s<br>", $error);
}
} else {
print "<input type='submit' value='dummy'>";
}
}
//ポストデータがなければ空文字を返す、あればその文字列を返す
function getPOST($key, $post_data) {
return (isset($post_data[$key])) ? $post_data[$key] : '';
}
//getPOSTの配列版
function getPOSTArray($key, $post_data) {
$ret = array();
if (!isset($post_data[$key]) || !is_array($post_data[$key])) return $ret;
foreach ($post_data[$key] as $key => $value) {
$ret += array($key => getFormatedText($value,0));
}
return $ret;
}
//ポストの値があれば表示、なければ空白を表示
function showPOST($key, $post_data) {
print getPOST($key, $post_data);
}
function showPrefectures() {
Prefecture_Data::constructSelectBox(getPOST('prefecture',$_POST));
}
function showHobbys($post_data, $hobby_list) {
foreach ($hobby_list as $key => $elm) {
$checked = '';
if (empty($check_list) == false) {
$checked = (in_array($elm, $check_list)) ? 'checked' : '';
}
printf("<input type='checkbox' id='%s' name='hobby[]' value='%s' %s><label for='%s'>%s</label>",
$key, $elm, $checked, $key, $elm);
}
printf("<input type='text' name='other_descript' id='other_descript value='%s'>", getPOST('other_descript', $post_data));
}
function writeHiddenParams($post_data, $name_list) {
foreach ($name_list as $name) {
$input = (isset($post_data[$name])) ? $post_data[$name] : '';
printf("<input type='hidden' name='%s' value='%s'>", $name, $input);
}
if (isset($post_data['hobby'])) {
foreach ($post_data['hobby'] as $hobby) {
printf("<input type='hidden' name='hobby[]' value='%s'>", $hobby);
}
}
//その他の趣味の詳細が入力されていたら、その他にチェックを付与
if (!empty($post_data['other_descript']) && !in_array('その他', $post_data['hobby'])) {
print "<input type='hidden' name='hobby[]' value='その他'>";
}
}
//showPrefectures();
include('form.html.php');