吐き出して <form> -- </form>tag と見えるように、入力を促す部分を作る。
print("<html>\n") print("<head>\n") print("<title>定番メニューよありがとう</title>\n") print("</head>\n") print("<body>\n") print("<h1>送信フォーム</h1>\n") printf("<form method=\"POST\" action=\"./%s\">\n",myprog) print("<p>学籍番号 : <input name=\"studentid\" maxlength=\"20\"><br><br>\n") print("名前 : <input name=\"studentname\" maxlength=\"20\"><br><br>\n") print("その理由 : <textarea name=\"comment\" cols=\"40\" rows=\"2\"></textarea><br><br>\n") print("<input type=\"submit\" value=\"送信\"><input type=\"reset\" value=\"リセット\"></p>\n") print("</form>\n") #データをため、結果を表示する部分
見かけが完成しているかどうか、該当するページをブラウザで見て調べよう。 http://roy/~ユーザ ID/rubycgi/mydb/プログラム名.rb である。
form tag を見ると、CGI 変数は studentid, studentname, comment である。 このときプログラムの中では cgi[studentid], cgi[studentname], cgi[comment] として取り扱う。
"" double quotation の部分は、CGI 変数と区別するために、 \"\" として表現する。