エディターのコンテンツは、ほとんどの場合、フォームの POST リクエストから取得されます。
<form action="process.php" method="POST">
<textarea name="text" id="editor"></textarea>
<input type="submit" value="Submit" />
</form>
そして、でprocess.php
:
<?php
$content = $_POST['text'];
echo $content;
?>
もちろん、これにいくつかの検証を追加する必要があります。ただし、これにより簡単なアイデアが得られ、開始できるはずです。
「フォーム処理 php」のように Google 検索を開始することもできます。
編集
これを行うには、何らかのサーバー側のアクションが必要です。これは純粋な HTML では不可能です。サーバー側のバックエンドを追加する必要があります。
これを説明するためのちょっとした図:
editor.html
| 変更をバックエンドに送信
v
バックエンド (フロントエンドの内容を変更)
|
v
content.html
これは (html ファイルの内容を直接変更するには) 非常に貧弱な設計ですが、原理は同じです。「良い」セットアップでは、コンテンツを保持するデータベースがあり、フロントエンドがそこからプルし、バックエンドがプッシュします。しかし、純粋な HTML ではこれは不可能です。
それでは、定型文をいくつか紹介しましょう。
index.php:
<html>
<head>
<!-- add more stuff here -->
</head>
<body>
<h1>Your Site</h1>
<!-- add more stuff here -->
<p>
<?php
echo file_get_contents('article.txt');
?>
</p>
<!-- add more stuff here -->
</body>
</html>
editor.html:
<html>
<head>
<!-- add more stuff here -->
</head>
<body>
<h1>Your Site - Editor</h1>
<!-- add more stuff here -->
<form action="process.php" method="POST">
<input type="password" name="pwd" placeholder="Password..." />
<textarea name="text" id="editor"></textarea>
<input type="submit" value="Submit" />
</form>
<!-- add more stuff here -->
</body>
</html>
プロセス.php:
<?php
if(!isset($_POST['text']) {
die('Please fill out the form at editor.html');
}
if($_POST['pwd'] !== 'your_password') {
die('Password incorrect');
}
file_put_contents('article.txt', $_POST['text']);
header("Location: index.php");
?>
これは非常に基本的なボイラープレートであり、開始するのに役立つはずです。微調整してください。