PHPでformからGETしたパラメータを別ページにフォワードする(DAM選曲)(2024.10.13)

Summary

phpでformを用いてGETしたパラメータを別のページにフォワードしたい。 <form action = [URL] method = "GET" target="_blank">を使用する。
動的に何かをする必要はなく、<input type = "hidden" name="name" value="value">で実現可能。

DAMの選曲番号をDAMのwebサイトで検索する

DAMのwebサイトでは、なぜか機種選択のタブが検索後にしか選べなくなっており、特定の機種に絞った検索がやりにくい。しかも日本語のページしかないので、海外からのゲストに持ち歌を検索してもらうのには不向き。などの理由で、検索の入口のページを作成することにした。

formのGET methodを使って取得したパラメータ(ここでは曲のタイトルやアーティスト名など)をform機能を使って入力してもらい、あらかじめ設定しておいた機種指定のパラメータとあわせてDAMのサイトにフォワードする。

DAMの検索サイトの仕様はGETで以下のパラメータを指定しているようだ。

固定のパラメータはtype=hiddenで指定する

DAMの選曲番号を検索するサイトの例

DAM選曲番号検索

index.phpの例

<?php
/*
========================================================================
  PHP8 test get params 'index.php'
========================================================================
*/
// set parameters
if(isset($_GET['keyword'])) {
  $keyword   = $_GET['keyword'];
  $keyword   = htmlspecialchars($_GET['keyword'], ENT_QUOTES, 'UTF-8');
  //echo $keyword;
} //else {
//  echo "input query words";
//}
/*
phpinfo();
*/
?>
<!DOCTYPE html>
<html lang = "ja">
<head>
<style>
.txt{
  display: inline-block;
  width: 100%;
  max-width: 800px;
  padding: 0.5em;
  border: 1px solid #999;
  box-sizing: border-box;
  margin: 0.5em 0;
}
</style>
<meta charset = "UTF=8">
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title> Search songs for PARTY DAM HD</title>
</head>
<body>
<h1>Search songs for Party DAM HD<br> DCASE 2024 Workshop: Dinner cruise</h1>
<!--
<form action = "https://www.clubdam.com/karaokesearch/" method = "GET"  target="_blank">
<form action = "index.php" method = "GET" target="_blank">
-->
<form action = "https://www.clubdam.com/karaokesearch/" method = "GET"  target="_blank">
<input type = "text" name="keyword" class="txt">
<input type = "hidden" name="type" value="keyword">
<input type = "hidden" name="contetnsCode" value="">
<input type = "hidden" name="serviceCode" value="">
<input type = "hidden" name="serialNo" value="AL00001">
<input type = "hidden" name="sort" value="2">
<input type = "submit" value ="Search" style="font-size:24px">
</form>

<p>Usage:</p>
<ol>
<li>Input keywords such as title of the song and/or the artist name.</li>
<li>Press the Search button.</li>
    <img src="fig001.png" width="200">
<li>Another window will show the list of songs.</li>
<li>Click the link to the target song and the DAM page will show the details.</li>
    <img src="fig002.png" width="200">
<li>Check the 4+2 digit song number denoted as: "選曲番号: 1234-56"</li>
    <img src="fig003.png" width="200">
<li>Set the 4+2 digit song number to the DAM-rimo.</li> 
</ol>

</body>
</html>

参考

Back to Index