$value) {
if ($key !== 'submit') {
$data_to_save[$key] = $value;
}
}
// Save if no errors occurred
if (empty($errors)) {
file_put_contents($json_file, json_encode($data_to_save, JSON_PRETTY_PRINT));
header("Location: " . $_SERVER['PHP_SELF']);
exit;
} else {
$error_message = implode("
", $errors);
}
}
// --- 2. Load Data for Display ---
$saved_data = [];
if (file_exists($json_file)) {
$json_content = file_get_contents($json_file); // Note: fixed typo from your snippet if it was file_get_contents
$json_content = file_get_contents($json_file);
$saved_data = json_decode($json_content, true) ?? [];
}
function getValue($data, $key)
{
return $data[$key] ?? '';
}
include 'header.php';
?>