質問編集履歴
1
加筆
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,4 +8,116 @@
|
|
8
8
|
|
9
9
|
何かそのあたりの説明が分かり易く載っているサイトなどあったら教えていただけると助かります。
|
10
10
|
|
11
|
-
よろしくお願いいたします。
|
11
|
+
よろしくお願いいたします。
|
12
|
+
|
13
|
+
〇追記:コード例
|
14
|
+
検証用に作成したコード、フレームワークcodeigniterを使用しています。
|
15
|
+
処理の流れは以下の感じ
|
16
|
+
|
17
|
+
1.申し込み画面(entry.php)
|
18
|
+
2.申し込みボタンを押してPOST
|
19
|
+
3.サーバー側で登録後、リダイレクト(Location: http://root/recruit/entry/complete_entry)
|
20
|
+
4.クライアントリダイレクト要求を受け取ってhttp://root/recruit/entry/complete_entryにリクエスト
|
21
|
+
|
22
|
+
ここで2のリファラが残らないのはなぜでしょうか。
|
23
|
+
|
24
|
+
```PHP
|
25
|
+
<!--view/entry.php-->
|
26
|
+
|
27
|
+
<?php echo validation_errors(); ?>
|
28
|
+
|
29
|
+
<?php echo form_open('entry/post'); ?>
|
30
|
+
<div class="wrapper">
|
31
|
+
<div class="entry_contents">
|
32
|
+
<div class="contents_label">
|
33
|
+
<label>お名前</label>
|
34
|
+
</div>
|
35
|
+
<div>
|
36
|
+
<input type="text" name="last_name" />
|
37
|
+
<input type="text" name="first_name" />
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div class="entry_contents">
|
42
|
+
<div class="contents_label">
|
43
|
+
<label>メールアドレス</label>
|
44
|
+
</div>
|
45
|
+
<div>
|
46
|
+
<input type="email" name="email" />
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<div class="entry_contents">
|
51
|
+
<div class="contents_label">
|
52
|
+
<label>電話番号</label>
|
53
|
+
</div>
|
54
|
+
<div>
|
55
|
+
<input type="text" name="phone_num" />
|
56
|
+
</div>
|
57
|
+
</div>
|
58
|
+
|
59
|
+
<input type="submit" name="post" value="申し込み"/>
|
60
|
+
</div>
|
61
|
+
</form>
|
62
|
+
```
|
63
|
+
|
64
|
+
|
65
|
+
```PHP
|
66
|
+
<?PHP
|
67
|
+
<!--controller/Entry.php-->
|
68
|
+
class Entry extends CI_Controller {
|
69
|
+
public function __construct()
|
70
|
+
{
|
71
|
+
parent::__construct();
|
72
|
+
$this->load->helper('url_helper');
|
73
|
+
$this->load->helper('func');
|
74
|
+
$this->load->library('form_validation');
|
75
|
+
}
|
76
|
+
|
77
|
+
public function post()
|
78
|
+
{
|
79
|
+
// entryモデルクラスロード。指定はすべて小文字で指定
|
80
|
+
$this->load->model('entry_model');
|
81
|
+
|
82
|
+
// バリデーションルールセット
|
83
|
+
$this->form_validation->set_rules('last_name', '姓', 'required');
|
84
|
+
$this->form_validation->set_rules('first_name', '名', 'required');
|
85
|
+
$this->form_validation->set_rules('email', 'メールアドレス', 'required|valid_email');
|
86
|
+
$this->form_validation->set_rules('phone_num', '電話番号', 'required');
|
87
|
+
|
88
|
+
// バリデーションチェック
|
89
|
+
if ($this->form_validation->run() === FALSE) {
|
90
|
+
// チェックエラー
|
91
|
+
$this->view_wapper('entry');
|
92
|
+
|
93
|
+
} else {
|
94
|
+
// 正常系
|
95
|
+
|
96
|
+
//データ登録
|
97
|
+
$this->entry_model->create_entry();
|
98
|
+
|
99
|
+
//PRGパターン。リダイレクト
|
100
|
+
header("Location: http://root/recruit/entry/complete_entry", false, 303);
|
101
|
+
exit();
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
public function complete_entry()
|
106
|
+
{
|
107
|
+
$this->view_wapper('entry_done');
|
108
|
+
}
|
109
|
+
|
110
|
+
public function index()
|
111
|
+
{
|
112
|
+
$this->view_wapper('entry');
|
113
|
+
}
|
114
|
+
|
115
|
+
private function view_wapper($contents)
|
116
|
+
{
|
117
|
+
$this->load->view('templates/header');
|
118
|
+
$this->load->view($contents);
|
119
|
+
$this->load->view('templates/footer');
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
```
|