Fix: IPD discharge template delete not working
ISSUE: Delete button executed but did not actually delete templates
ROUTE: /setting/template/discharge_templates/delete/{id}
ROOT CAUSE:
The delete button's fetch() call was sending 'new FormData(form)' which:
1. Included entire edit form data (template_html, header_html, footer_html)
2. These are HUGE LONGTEXT fields that can cause request payload issues
3. CSRF token from form might be stale or missing if no template is being edited
4. Server received malformed request and silently failed
SOLUTION:
- Create fresh FormData with ONLY the CSRF token
- Delete request now lightweight and reliable
- Added success message display after successful delete
- Server-side delete logic already correct (line 2969-3028 in Template.php)
CHANGED:
- app/Views/Setting/Template/discharge_templates.php (line 618-653)
- Replace: body: new FormData(form)
- With: body: deleteFormData (contains only CSRF token)
- Added: setNotice('success', ...) to show success message
TESTING:
1. Go to /setting/template/discharge_templates
2. Click Delete on any non-default template
3. Confirm deletion
4. Template should now be removed from list
5. Success message should display
This commit is contained in:
parent
a929100d4d
commit
d025111bcc
|
|
@ -626,9 +626,13 @@ $status = (int) ($edit['status'] ?? 1);
|
|||
return;
|
||||
}
|
||||
|
||||
// Create fresh FormData with only CSRF token
|
||||
var deleteFormData = new FormData();
|
||||
deleteFormData.append('<?= csrf_token() ?>', '<?= csrf_hash() ?>');
|
||||
|
||||
fetch('<?= base_url('setting/template/discharge_templates/delete') ?>/' + id, {
|
||||
method: 'POST',
|
||||
body: new FormData(form),
|
||||
body: deleteFormData,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
|
|
@ -641,6 +645,8 @@ $status = (int) ($edit['status'] ?? 1);
|
|||
return;
|
||||
}
|
||||
|
||||
setNotice('success', data.error_text || 'Template deleted successfully.');
|
||||
|
||||
if (typeof load_form_div === 'function') {
|
||||
load_form_div('<?= base_url('setting/template/discharge_templates') ?>', 'maindiv', 'IPD Discharge Template');
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user