HTMLで表示

Dockerのsrc以下のフォルダがApacheの/var/www/htmlのフォルダに同期されている

docker-compose.ymlの設定volumes:以下)

1
2
3
4
5
6
7
8
9
10
app:
build:
context: .
dockerfile: docker/app/Dockerfile
ports:
- "50080:80"
volumes:
- ./src:/var/www/html
depends_on:
- db`

src以下のフォルダに置いたファイルには、ブラウザから

localhost:50080/ファイルのパスで表示できる

ページの表示

src直下にnew.phpを配置

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHPファイルでHTMLを表示</title>
</head>
<body>
<h1>HELLO WORLD!</h1>
</body>
</html>

ブラウザのアドレスにhttp://localhost:50080/new.phpを指定するとHTMLが表示される

HTMLのフォーム

フォームとは「お問い合わせ」「会員登録」など、ユーザーが入力処理を行うために使用されるもの

1
2
3
4
<form action="create.php" method="post">
<label for="name">名前</label>
<input type="text" name="name" id="name">
<button type="submit">登録する</button>
  • formタグ: フォームを作成する
  • actionタグ: 送信ボタンを押した後に移動するページ
  • method: データの送信方法GETかPOSTを指定。登録系のときはPOSTを指定
  • labelタグ: フォームのラベルを作成する
  • for パーツのid属性と同じ値にすることでパーツをラベルを関連づけられる
  • input type=”text”: 1行のテキストエリアを設置する
  • name: パーツの名前。PHPにデータを送信する際の項目名になる

    ラジオボタン

    ラジオボタンにすることで複数から一つを選ばせることができる。

    nameの名前を同じにするとグループ化できる
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <form action="create.php" method="post">
    <div>
    <input type="radio" name="sex" id="male" value="male">
    <label for="male">男性</label>
    </div>
    <div>
    <input type="radio" name="sex" id="female" value="female">
    <label for="female">女性</label>
    </div>
    <button type="submit">登録する</button>