<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>データ入力時のみデータを処理するには?</title>
</head>
<body>
<?php
$example = isset($_POST['example']) ? $_POST['example'] : NULL;
if (strlen($example) > 0) {
echo '<p>データを受け取りました: ' . h($example) . '</p>';
} else {
echo "<p>データを受け取っていません</p>";
}
function h($string) {
return htmlspecialchars($string, ENT_QUOTES);
}
?>
<form method="post" action="">
<p>テキストボックス</p>
<input type="text" name="example" />
<input type="submit" value="送信" />
</form>
</body>
</html>