リターンキーからのForm送信チェック
<?php
$str = $_POST['text'];
if ($str != null){
$result = "あなたは、「{$str}」と書きました。";
} else {
$result = "なにか書いてください。";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8" />
<title>sample page</title>
<script type="text/javascript" charset="UTF-8">
function submitCheck(e){
if (!e) var e = window.event;
if(e.keyCode == 13){
if(confirm('送信してもよろしいですか?')){
input = e.srcElement? e.srcElement: e.target;
var form = input.parentNode;
while(form != null && form.nodeName != 'FORM'){
form = form.parentNode;
}
if(form != null)
form.submit();
}
else {
return false;
}
}
}
</script>
</head>
<body>
<h1>Form Check!</h1>
<div><?php echo $result; ?></div>
<form method="post" action="<?php echo $PHP_SELF; ?>">
<input type = "text" name = "text" onKeyPress="return submitCheck(event);">
<input type = "submit" name = "button1" value = "送信">
</form>
<hr>
</body>
</html>
ディレクトリ内のファイルを表示、ジャンプリスト
<?php
if ($_POST != null && $_POST !=null){
$url = $_POST['jump'];
header("Location:{$url}");
}
$dir = ".";
$filedir = str_replace( "\\" , "/" , dirname(__FILE__) );
?>
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8" />
<title>List & Link PHP</title>
</head>
<body>
<h1>List & Link PHP!</h1>
<p><?php echo $filedir; ?></p>
<hr>
<form method="post" action="<?php echo $PHP_SELF; ?>">
<select name="jump" size="10">
<?php
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<option value=\"".$file."\">".$file."</option>\n";
}
closedir($dh);
}
}
?>
</select>
<input type="submit" value="移動">
</form>
<hr>
</body>
</html>