phpwork/submit.php
2025-03-27 08:52:00 +08:00

157 lines
4.7 KiB
PHP

<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title'] ?? '');
$content = trim($_POST['content'] ?? '');
$category = $_POST['category'] ?? '';
if (!empty($title) && !empty($content) && !empty($category)) {
$id = uniqid();
$_SESSION['news'][$id] = [
'title' => $title,
'content' => $content,
'category' => $category,
'time' => date('Y-m-d H:i:s')
];
$success = true;
} else {
$error = true;
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新闻发布 - 2025</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
:root {
--primary-color: #2c3e50;
--secondary-color: #3498db;
--success-color: #27ae60;
--danger-color: #e74c3c;
}
body {
background-color: #f8f9fa;
min-height: 100vh;
}
.gradient-header {
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
color: white;
padding: 2rem;
border-radius: 12px;
margin-bottom: 2rem;
}
.form-control-custom {
border: 2px solid #e0e0e0;
border-radius: 8px;
padding: 12px;
transition: border-color 0.3s ease;
}
.submit-btn {
background-color: var(--success-color);
color: white;
padding: 12px 30px;
border: none;
border-radius: 25px;
font-weight: bold;
transition: transform 0.2s ease;
}
.alert-message {
position: fixed;
top: 20px;
right: 20px;
z-index: 1000;
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from { transform: translateX(100%); }
to { transform: translateX(0); }
}
</style>
</head>
<body>
<nav class="navbar navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="#">Placeholder</a>
<div class="d-flex">
<a href="submit.php" class="text-white me-3">发布新闻</a>
<a href="display.php" class="text-white">查看新闻</a>
</div>
</div>
</nav>
<div class="container py-5" style="max-width: 800px;">
<?php if(isset($success)): ?>
<div class="alert alert-success alert-message">
新闻发布成功!<a href="display.php" class="alert-link">查看新闻</a>
</div>
<?php elseif(isset($error)): ?>
<div class="alert alert-danger alert-message">
请填写所有必填字段!
</div>
<?php endif; ?>
<div class="gradient-header text-center">
<h1>发布新闻</h1>
<p class="mb-0">分享2025最新资讯</p>
</div>
<form method="post" class="bg-white p-4 rounded-3 shadow-sm">
<div class="mb-4">
<label class="form-label fw-bold">新闻标题</label>
<input type="text" name="title" class="form-control form-control-custom" required>
</div>
<div class="mb-4">
<label class="form-label fw-bold">新闻内容</label>
<textarea name="content" class="form-control form-control-custom" rows="5" required></textarea>
</div>
<div class="mb-4">
<label class="form-label fw-bold">新闻类别</label>
<div class="d-flex flex-wrap gap-3">
<?php foreach(['A', 'B', 'C', 'D'] as $type): ?>
<div class="form-check">
<input class="form-check-input" type="radio" name="category"
value="<?= $type ?>" id="<?= $type ?>" required>
<label class="form-check-label" for="<?= $type ?>"><?= $type ?></label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="text-center mt-4">
<button type="submit" class="submit-btn">立即发布</button>
</div>
</form>
</div>
<footer class="bg-light text-center py-3 mt-5">
<div class="container">
<span class="text-muted">© 2025 @Theresa.ltd</span>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// 自动隐藏提示信息
setTimeout(() => {
document.querySelectorAll('.alert-message').forEach(alert => {
alert.remove();
});
}, 5000);
</script>
</body>
</html>