Commit badef7ea authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: branding save uses API directly (not form POST) — reliable Supabase persistence

Problem: Form POST to same page required PHP session + page re-render.
Save appeared to work but values weren't persisting to Supabase reliably.

Fix: Save button now POSTs to /api/branding.php directly as JSON.
- Collects all input values from DOM
- Sends { action: 'save_theme', values: { key: value, ... } }
- API writes each value to platform_theme table (upsert)
- No session dependency, no form submission, no page reload
- Response confirms success/failure with message

On page refresh: PHP reads from platform_theme → shows saved values Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 67c6136f
...@@ -539,29 +539,42 @@ function saveAll() { ...@@ -539,29 +539,42 @@ function saveAll() {
saveBtn.textContent = 'Saving...'; saveBtn.textContent = 'Saving...';
saveBtn.style.opacity = '0.6'; saveBtn.style.opacity = '0.6';
const form = document.querySelector('form[method="POST"]:not([enctype])'); // Collect all theme values from inputs
if (!form) return; const values = {};
const formData = new FormData(form); document.querySelectorAll('input[name^="theme["]').forEach(input => {
formData.append('save_theme', '1'); const match = input.name.match(/theme\[(.+?)\]/);
if (match && input.value) {
fetch(window.location.href, { method: 'POST', body: formData }) values[match[1]] = input.value;
.then(r => { }
if (r.ok) { });
// Save directly to Supabase via API (reliable, no session dependency)
fetch('/api/branding.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'save_theme', values })
})
.then(r => r.json())
.then(data => {
if (data.success) {
hasChanges = false; hasChanges = false;
saveBtn.textContent = '✓ Saved!'; saveBtn.textContent = '✓ Saved!';
saveBtn.style.opacity = '0.5'; saveBtn.style.opacity = '0.5';
saveBtn.style.pointerEvents = 'none'; saveBtn.style.pointerEvents = 'none';
saveStatus.textContent = '✓ All changes saved'; saveStatus.textContent = '✓ All changes saved to database';
saveStatus.style.color = '#34D399'; saveStatus.style.color = '#34D399';
setTimeout(() => { setTimeout(() => {
saveBtn.textContent = '💾 Save All'; saveBtn.textContent = '💾 Save All';
saveStatus.textContent = 'No unsaved changes'; saveStatus.textContent = 'No unsaved changes';
saveStatus.style.color = '#64748b'; saveStatus.style.color = '#64748b';
}, 2000); }, 2000);
} else {
saveBtn.textContent = '❌ Error: ' + (data.error || 'unknown');
saveBtn.style.opacity = '1';
} }
}) })
.catch(() => { .catch((err) => {
saveBtn.textContent = '❌ Error — retry'; saveBtn.textContent = '❌ Network error — retry';
saveBtn.style.opacity = '1'; saveBtn.style.opacity = '1';
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment