質問編集履歴
1
フォームが送られてくる先の確認画面のソース・バリデーションのソース、ddコマンド出力を記載しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
コード
|
4
|
+
|
1
|
-
Laravel5.6で名刺管理アプリを作成しています。
|
5
|
+
```Laravel5.6で名刺管理アプリを作成しています。
|
2
6
|
|
3
7
|
|
4
8
|
|
@@ -97,3 +101,159 @@
|
|
97
101
|
なぜこのようなpostが送られてしまっているのか、わかりません。
|
98
102
|
|
99
103
|
ご教授いただけると幸いです。
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
フォームが送られる確認画面(confirm)では以下の処理を行います。
|
108
|
+
|
109
|
+
```php
|
110
|
+
|
111
|
+
public function confirm(Request $request)
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
dd($request);
|
116
|
+
|
117
|
+
$validator = $this->getValidator($request);
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
//バリデーションチェックが通らなかったらフォーム画面にリダイレクト
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
if ($validator->fails()) {
|
126
|
+
|
127
|
+
// フォーム画面ヘリダイレクト
|
128
|
+
|
129
|
+
return redirect('form')
|
130
|
+
|
131
|
+
->withErrors($validator)
|
132
|
+
|
133
|
+
->withInput();
|
134
|
+
|
135
|
+
} else {
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
// 確認画面を表示する*/
|
140
|
+
|
141
|
+
return view('confirm');
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
バリデーターの処理は以下の通りです。
|
154
|
+
|
155
|
+
```php
|
156
|
+
|
157
|
+
//confirm画面・result画面で使用するバリデーションのルール
|
158
|
+
|
159
|
+
public function getValidator(array $Input)
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
$rules = [
|
164
|
+
|
165
|
+
'name' => 'required|string|max:60',
|
166
|
+
|
167
|
+
'company' => 'required|string|max:60',
|
168
|
+
|
169
|
+
'tel' => 'required|numeric|digits_between:10,11',
|
170
|
+
|
171
|
+
'address' => 'required|string|max:60',
|
172
|
+
|
173
|
+
'email' => 'required|email'];
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
$validator = Validator::make($Input, $rules);
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
return $validator;
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
フォームの名前・会社名・電話番号・住所・emailすべてを埋めた状態で送った
|
190
|
+
|
191
|
+
ddコマンドの出力は以下の通りです。
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
```php
|
196
|
+
|
197
|
+
Request {#55 ▼
|
198
|
+
|
199
|
+
#json: null
|
200
|
+
|
201
|
+
#convertedFiles: null
|
202
|
+
|
203
|
+
#userResolver: Closure {#320 ▶}
|
204
|
+
|
205
|
+
#routeResolver: Closure {#343 ▶}
|
206
|
+
|
207
|
+
+attributes: ParameterBag {#65 ▶}
|
208
|
+
|
209
|
+
+request: ParameterBag {#64 ▶}
|
210
|
+
|
211
|
+
+query: ParameterBag {#63 ▶}
|
212
|
+
|
213
|
+
+server: ServerBag {#67 ▶}
|
214
|
+
|
215
|
+
+files: FileBag {#60 ▶}
|
216
|
+
|
217
|
+
+cookies: ParameterBag {#66 ▶}
|
218
|
+
|
219
|
+
+headers: HeaderBag {#68 ▶}
|
220
|
+
|
221
|
+
#content: null
|
222
|
+
|
223
|
+
#languages: null
|
224
|
+
|
225
|
+
#charsets: null
|
226
|
+
|
227
|
+
#encodings: null
|
228
|
+
|
229
|
+
#acceptableContentTypes: null
|
230
|
+
|
231
|
+
#pathInfo: "/confirm"
|
232
|
+
|
233
|
+
#requestUri: "/confirm"
|
234
|
+
|
235
|
+
#baseUrl: ""
|
236
|
+
|
237
|
+
#basePath: null
|
238
|
+
|
239
|
+
#method: "POST"
|
240
|
+
|
241
|
+
#format: null
|
242
|
+
|
243
|
+
#session: Store {#399 ▶}
|
244
|
+
|
245
|
+
#locale: null
|
246
|
+
|
247
|
+
#defaultLocale: "en"
|
248
|
+
|
249
|
+
-isHostValid: true
|
250
|
+
|
251
|
+
-isForwardedValid: true
|
252
|
+
|
253
|
+
basePath: ""
|
254
|
+
|
255
|
+
format: "html"
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
```
|