diff --git a/src/pages/php/030-form.mdx b/src/pages/php/030-form.mdx index 862b6b2..8ca662a 100644 --- a/src/pages/php/030-form.mdx +++ b/src/pages/php/030-form.mdx @@ -16,7 +16,9 @@ ## TOC -こんなフォームがあったとします。 +## フォームを用意する + +例として、以下のようなフォームを用意しました。 @@ -34,11 +36,27 @@ `method`属性は、深くは触れませんがデータを使って何をしてほしいのかを大まかにサーバーに伝えるためのものです。 この`method`属性には主に`GET`と`POST`の2つがありますが、今回は`POST`を使います。 -`GET`は、主にサーバーからなにか情報を取得したいときに指定します。 -対して`POST`はデータ取得以外の処理をしてほしいときに指定することが多いです。 - ```html "action=\"./submit.php\"" "method=\"post\""
... + +
``` + +## 送信先を用意する + +このセクションでは、`submit.php`を作成します。 +説明のために、このファイルがどのような考えのもとに作成されているかを順番に解説します。 + +### 雛形を作成する + +まず、送信先の`submit.php`を作成します。 +ここでどんなデータを受け取ったかに関わらず、どのような見た目にするかを決めるための雛形を作成しています。 + + + +```html file=src/sample/php/form/1/submit.php +src/sample/php/form/1/submit.php +内容を取得できませんでした +``` diff --git a/src/sample/php/form.html b/src/sample/php/form.html index d46135e..bacdf57 100644 --- a/src/sample/php/form.html +++ b/src/sample/php/form.html @@ -11,17 +11,17 @@
- +
- +
- @@ -34,11 +34,6 @@
-
- - -
-
diff --git a/src/sample/php/form/1/form.html b/src/sample/php/form/1/form.html new file mode 120000 index 0000000..9cff431 --- /dev/null +++ b/src/sample/php/form/1/form.html @@ -0,0 +1 @@ +../../form.html \ No newline at end of file diff --git a/src/sample/php/form/1/submit.php b/src/sample/php/form/1/submit.php new file mode 100644 index 0000000..17b743e --- /dev/null +++ b/src/sample/php/form/1/submit.php @@ -0,0 +1,55 @@ + + + + + + + 応募完了 + + + + + +
+
応募ありがとうございました!
+ + + + + + + + + + + + + + +
お名前
住所
応募する商品
+ + 応募ページに戻る +
+ + + diff --git a/src/sample/php/form/2/form.html b/src/sample/php/form/2/form.html new file mode 120000 index 0000000..9cff431 --- /dev/null +++ b/src/sample/php/form/2/form.html @@ -0,0 +1 @@ +../../form.html \ No newline at end of file diff --git a/src/sample/php/form/2/submit.php b/src/sample/php/form/2/submit.php new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/sample/php/form/2/submit.php diff --git a/src/sample/php/form/3/form.html b/src/sample/php/form/3/form.html new file mode 120000 index 0000000..9cff431 --- /dev/null +++ b/src/sample/php/form/3/form.html @@ -0,0 +1 @@ +../../form.html \ No newline at end of file diff --git a/src/sample/php/form/3/submit.php b/src/sample/php/form/3/submit.php new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/sample/php/form/3/submit.php diff --git a/src/sample/php/form/4/form.html b/src/sample/php/form/4/form.html new file mode 120000 index 0000000..9cff431 --- /dev/null +++ b/src/sample/php/form/4/form.html @@ -0,0 +1 @@ +../../form.html \ No newline at end of file diff --git a/src/sample/php/form/4/submit.php b/src/sample/php/form/4/submit.php new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/sample/php/form/4/submit.php diff --git a/src/sample/php/form/5/form.html b/src/sample/php/form/5/form.html new file mode 120000 index 0000000..9cff431 --- /dev/null +++ b/src/sample/php/form/5/form.html @@ -0,0 +1 @@ +../../form.html \ No newline at end of file diff --git a/src/sample/php/form/5/submit.php b/src/sample/php/form/5/submit.php new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/sample/php/form/5/submit.php diff --git a/src/sample/php/submit.php b/src/sample/php/submit.php index 832f88c..8f5ceb7 100644 --- a/src/sample/php/submit.php +++ b/src/sample/php/submit.php @@ -1,14 +1,12 @@ '; - echo var_export($var); - echo ''; -} +$views = [ + "./submit/1.php", +]; +$latest = count($views) - 1; -echo var_output($_SERVER); -echo var_output($_GET); -echo var_output($_POST); -?> +// ここを表示したいビューのインデックスに変更することで、表示内容を切り替えられます +$index = $latest; +// 対象のファイルの中身をコピーして、ここにペーストするような処理 +require_once $views[$index];