Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Last active August 29, 2015 14:25
Show Gist options
  • Save masakielastic/6e3e9cbfd02b7dd7140c to your computer and use it in GitHub Desktop.
Save masakielastic/6e3e9cbfd02b7dd7140c to your computer and use it in GitHub Desktop.
1つのファイルで設定画面の練習
<?php
$user = json_decode(file_get_contents('user.json'), true);
if (isset($_POST['email'])) {
$email = $_POST['email'];
$msg = '更新しました。';
$user = ['email' => $email];
file_put_contents('user.json', json_encode($user));
} else {
$email = isset($user['email']) ? $user['email'] : '';
$msg = '';
}
$email = htmlspecialchars($email, ENT_QUOTES, 'UTF-8');
?>
<div>
<form action="/test/index.php" method="POST">
<p>
<label for="email">メールアドレス</label>
<input type="text" id="email" name="email" value="<?= $user['email'] ?>"/>
</p>
<p>
<?= $msg ?>
</p>
<p>
<input type="submit" value="更新する"/>
</p>
</form>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment