style: 好讀版稿本2
This commit is contained in:
@@ -1,52 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* 水晶男孩入坑申請書(表單練習用)
|
||||
* POST 送回本頁;尚未寫入資料庫。
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
function fansform_h(?string $value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function fansform_post(string $key, string $default = ''): string
|
||||
{
|
||||
return isset($_POST[$key]) ? (string) $_POST[$key] : $default;
|
||||
}
|
||||
|
||||
function fansform_post_array(string $key): array
|
||||
{
|
||||
if (!isset($_POST[$key]) || !is_array($_POST[$key])) {
|
||||
return [];
|
||||
}
|
||||
return array_map('strval', $_POST[$key]);
|
||||
}
|
||||
|
||||
$isPost = $_SERVER['REQUEST_METHOD'] === 'POST';
|
||||
$submitted = false;
|
||||
$errors = [];
|
||||
|
||||
if ($isPost) {
|
||||
$nickname = trim(fansform_post('fan_nickname'));
|
||||
$email = trim(fansform_post('fan_email'));
|
||||
|
||||
if ($nickname === '') {
|
||||
$errors['fan_nickname'] = '請填寫應援小黃暱稱';
|
||||
}
|
||||
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors['fan_email'] = '請填寫有效的聯絡信箱';
|
||||
}
|
||||
|
||||
if ($errors === []) {
|
||||
$submitted = true;
|
||||
}
|
||||
}
|
||||
|
||||
$biasChecked = ($isPost && !$submitted) ? fansform_post_array('bias') : [];
|
||||
$eventPoll = fansform_post('event_poll');
|
||||
$favoriteSong = fansform_post('favorite_song');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-TW">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user