Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class=”comment”>
- <p>Автор:</p>
- <p>Комментарий:</p>
- <p>Время комментария</p>
- <div>
- <?php
- function checkData()
- {
- if (!empty ($_GET ['userName']) and !empty($_GET['content'])) {
- return true;
- }
- return false;
- }
- function saveComment($author, $content)
- {
- $res = file_put_contents('test2.php', $author . ':' . $content . ':' . time() . ':', FILE_APPEND);
- if ($res === false) {
- echo 'Запись не удалась...';
- } else {
- header('Location: test2.php?msg=success');
- }
- }
- if (!empty($_GET['formName']) and $_GET['formName'] == 'commentForm') {
- if (checkData()) {
- saveComment($_GET['userName'], $_GET['content']);
- } else exit('Все поля обязательны для заполнения');
- }
- ?>
- <?php if ($_GET['msg'] == 'success'): ?>
- <p>Комментарий успешно добавлен</p>
- <?php endif; ?>
- <form>
- <input type="text" name="userName"><br>
- <textarea name="content"></textarea><br>
- <input type="hidden" name="formName" value="commentForm">
- <button>Submit</button>
- </form>
Add Comment
Please, Sign In to add comment