Last active
August 29, 2015 14:25
-
-
Save masakielastic/6e3e9cbfd02b7dd7140c to your computer and use it in GitHub Desktop.
1つのファイルで設定画面の練習
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"email":"[email protected]"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment