diff --git a/encoder/app.php b/encoder/app.php index 4c3e787..8a51f47 100644 --- a/encoder/app.php +++ b/encoder/app.php @@ -15,29 +15,7 @@ $error_message = ''; if (isset($_POST['submit'])) { $errors = []; - // Handle Text Fields - $text_fields = [ - 'channel_name', - 'office_address', - 'office_address_1', - 'office_address_2', - 'contact_name_1', - 'contact_number_1', - 'contact_name_2', - 'contact_number_2', - 'contact_name_3', - 'contact_number_3', - 'enforcement_officer', - 'enforcement_officer_contact', - 'company_name', - 'cin_number', - 'gstin_number', - 'content_type', - 'content_rating', - 'content_language' - ]; - - // Dynamically build the list based on what is actually posted to handle the 3 contacts + // Dynamically build the list based on what is actually posted $data_to_save = []; foreach ($_POST as $key => $value) { if ($key !== 'submit') { @@ -47,18 +25,23 @@ if (isset($_POST['submit'])) { // Save if no errors occurred if (empty($errors)) { - file_put_contents($json_file, json_encode($data_to_save, JSON_PRETTY_PRINT)); + if (file_put_contents($json_file, json_encode($data_to_save, JSON_PRETTY_PRINT)) === false) { + $errors[] = "Failed to write to file. Check permissions."; + } + } + + if (!empty($errors)) { + $error_message = implode("
", $errors); + } else { + // Redirect to prevent form resubmission on refresh 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) ?? []; } @@ -91,7 +74,7 @@ include 'header.php'; -
+
@@ -101,7 +84,7 @@ include 'header.php';
- +
@@ -115,7 +98,7 @@ include 'header.php'; -
+
@@ -166,10 +149,10 @@ include 'header.php';