Web アプリ入門 / ch05 — HTML form を組み立てて受け取る / 演習 01

📝 ドリル 01 — 登録フォームの HTML を出力する

問題

次の HTML を そっくりそのまま 出力する PHP を書いてください。

<form action="/register" method="post">
<input type="text" name="name">
<input type="email" name="email">
<button type="submit">送信</button>
</form>

各タグは 1 行ずつ echo すること (改行の入れ方も期待値に合わせる)。

このドリルでは標準入力は使いません。

期待される出力:

<form action="/register" method="post">
<input type="text" name="name">
<input type="email" name="email">
<button type="submit">送信</button>
</form>

採点

php scripts/grade.php topics/12-web/ch05-html-form/drill/01-build-form-html/

ヒント

echo "<form action=\"/register\" method=\"post\">\n";
echo "<input type=\"text\" name=\"name\">\n";
// ...
▶ 3v4l で実行

シングルクォート文字列を使えばエスケープが要らない:

echo '<form action="/register" method="post">' . "\n";
▶ 3v4l で実行

テストケース

期待される出力

<form action="/register" method="post">
<input type="text" name="name">
<input type="email" name="email">
<button type="submit">送信</button>
</form>

📄 starter.php(雛形)

このコードから書き始めてください。

<?php

// TODO: 以下の HTML を 1 行ずつ echo する
//   <form action="/register" method="post">
//   <input type="text" name="name">
//   <input type="email" name="email">
//   <button type="submit">送信</button>
//   </form>
✅ 解答例を見る(自分で解いてから)
<?php

echo '<form action="/register" method="post">' . "\n";
echo '<input type="text" name="name">' . "\n";
echo '<input type="email" name="email">' . "\n";
echo '<button type="submit">送信</button>' . "\n";
echo '</form>' . "\n";