LoginSignup
0
0

More than 5 years have passed since last update.

【PHP】 GETを使った受け渡しの備忘録01

Last updated at Posted at 2018-09-01

メールフォームの基礎GETを使ったファイル間での受け渡しの備忘録です。

流れ

  1. index.htmlのsubmitボタンを押すと、tanks.phpに遷移
  2.  formタグの中にあるinputタグのnameと入力値(value)の組み合わせが(name)=(value)という形でurlに追加される
  3. inputタグが複数ある場合は&で繋げる

送信元 index.html

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>index.html</title>
</head>
<body>
  <h1>index.html</h1>
  <form action="thanks.php">
    /<!-- nameの値がthanks.phpに送られる -->
    <p>お名前:<input type="text" name="name"></p>
    <p>年齢:<input type="text" name="nenrei"></p>
    <p><button type="submit">送信</button></p>
  </form>
</body>
</html>

1.png

送信先 thanks.php

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>thanks.html</title>
</head>
<body>
  <h1>thanks.html</h1>
  <p>お名前:<?php echo $_GET['name'] ?></p>
  <p>年齢:<?php echo $_GET['nenrei'] ?>  </p>
</body>
</html>

2.png

メモ

  • フォームはあくまでリンク
  • URLのパラメータについている値を取得する
  • フォームに入力した値を取得しているのではなく、あくまでパラメータについてる値(そのため、ただのリンクの動きになる)

参考文献

WEBデザイナー・HTMLコーダーのための実践PHP入門 (1) メールフォームを自作する
https://www.udemy.com/phpbasics01/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0